dialysis_api_controller.go 384KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "math"
  7. "net/http"
  8. "net/url"
  9. "reflect"
  10. "strconv"
  11. "strings"
  12. "time"
  13. "XT_New/enums"
  14. "XT_New/models"
  15. "XT_New/service"
  16. "XT_New/utils"
  17. "github.com/astaxie/beego"
  18. "github.com/jinzhu/gorm"
  19. )
  20. // type DialysisTestAPIController struct {
  21. // MobileBaseAPIController
  22. // }
  23. // [get]/m/api/test
  24. // func (this *DialysisTestAPIController) Test() {
  25. // orgID := int64(3907)
  26. // now := time.Now()
  27. // nextWeek := now.AddDate(0, 0, 7)
  28. // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
  29. // nextTwoWeek := now.AddDate(0, 0, 14)
  30. // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
  31. // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
  32. // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
  33. // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
  34. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. // return
  36. // }
  37. // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
  38. // if exchangeErr != nil {
  39. // this.ErrorLog("%v", exchangeErr)
  40. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  41. // return
  42. // }
  43. // this.ServeSuccessJSON(map[string]interface{}{
  44. // // "now": now,
  45. // // "next_week": nextWeek,f
  46. // // "next_week_mon": nextWeekMon,
  47. // // "next_week_sun": nextWeekSun,
  48. // // "next_two_week_mon": nextTwoWeekMon,
  49. // // "next_two_week_sun": nextTwoWeekSun,
  50. // "next_week_schs": nextWeekSchs,
  51. // "next_two_week_schs": nextTwoWeekSchs,
  52. // })
  53. // }
  54. type DialysisAPIController struct {
  55. MobileBaseAPIAuthController
  56. }
  57. // /m/api/scheduals [get]
  58. // @param type:int
  59. // @param date:string
  60. func (this *DialysisAPIController) Scheduals() {
  61. schedualType, _ := this.GetInt64("type")
  62. schedualDate := this.GetString("date")
  63. if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
  64. schedualType = 0
  65. }
  66. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  67. if parseDateErr != nil {
  68. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  69. return
  70. }
  71. adminInfo := this.GetMobileAdminUserInfo()
  72. orgID := adminInfo.Org.Id
  73. redis := service.RedisClient()
  74. defer redis.Close()
  75. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  76. //redis.Set(key, "", time.Second)
  77. scheduals_json_str, _ := redis.Get(key).Result()
  78. patients, _ := service.GetAllPatientListSix(orgID)
  79. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  80. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  81. for _, item := range scheduals {
  82. order, _ := service.GetMonitDialysisOrder(item.UserOrgId, item.PatientId, date.Unix())
  83. item.DialysisLastOrder = order
  84. solution, _ := service.GetMonitDialysisSolution(item.UserOrgId, item.PatientId, item.ModeId)
  85. item.DialysisSolution = solution
  86. }
  87. if err != nil {
  88. this.ErrorLog("获取排班信息失败:%v", err)
  89. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  90. } else {
  91. if len(scheduals) > 0 {
  92. devices, _ := service.GetAllDevicetByListSix(orgID)
  93. advices, _ := service.GetAllAdvicestByList(orgID, date.Unix())
  94. prescriptions, _ := service.GetAllPrescriptionsByList(orgID, date.Unix())
  95. assessmentBefores, _ := service.GetAllAssessmentBeforesByList(orgID, date.Unix())
  96. dialysisOrders, _ := service.GetAllDialysisOrdersByList(orgID, date.Unix())
  97. treatmentSummarys, _ := service.GetAllTreatmentSummarysByList(orgID, date.Unix())
  98. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByList(orgID, date.Unix())
  99. dobulecheck, _ := service.GetAllDobuleCheckList(orgID, date.Unix())
  100. hisAdvices, _ := service.GetAllHisAdvicesByList(orgID, date.Unix())
  101. inforMation, _ := service.GetTodayInforMation(orgID, date.Unix())
  102. //monitor, _ := service.GetMonitorByListSix(orgID, date.Unix())
  103. for key, item := range scheduals {
  104. for _, infor := range inforMation {
  105. if item.PatientId == infor.PatientId && item.BedId == infor.BedNumber {
  106. scheduals[key].NewDeviceInformation = infor
  107. break
  108. }
  109. }
  110. // 获取患者信息
  111. for _, patient := range patients {
  112. if item.PatientId == patient.ID {
  113. scheduals[key].SchedualPatient = patient
  114. break
  115. }
  116. }
  117. // 床位信息
  118. for _, device := range devices {
  119. if item.BedId == device.ID {
  120. scheduals[key].DeviceNumber = device
  121. break
  122. }
  123. }
  124. // 医嘱信息
  125. scheduals[key].Advices = make([]models.VMDoctorAdviceForList, 0)
  126. for _, advice := range advices {
  127. if item.PatientId == advice.PatientId {
  128. scheduals[key].Advices = append(scheduals[key].Advices, advice)
  129. }
  130. }
  131. // 医嘱信息
  132. scheduals[key].HisAdvices = make([]service.VMHisDoctorAdviceInfo, 0)
  133. for _, hisAdvice := range hisAdvices {
  134. if item.PatientId == hisAdvice.PatientId {
  135. scheduals[key].HisAdvices = append(scheduals[key].HisAdvices, hisAdvice)
  136. }
  137. }
  138. // 医嘱信息
  139. for _, prescription := range prescriptions {
  140. if item.PatientId == prescription.PatientId {
  141. scheduals[key].Prescription = prescription
  142. break
  143. }
  144. }
  145. // 透前评估
  146. for _, assessmentBefore := range assessmentBefores {
  147. if item.PatientId == assessmentBefore.PatientId {
  148. scheduals[key].AssessmentBeforeDislysis = assessmentBefore
  149. break
  150. }
  151. }
  152. // 透析上下机
  153. for _, dialysisOrder := range dialysisOrders {
  154. if item.PatientId == dialysisOrder.PatientId {
  155. scheduals[key].DialysisOrder = dialysisOrder
  156. break
  157. }
  158. }
  159. // 治疗小节
  160. for _, afterDislysis := range AssessmentAfterDislysis {
  161. if item.PatientId == afterDislysis.PatientId {
  162. scheduals[key].AssessmentAfterDislysis = afterDislysis
  163. break
  164. }
  165. }
  166. // 透后评估
  167. for _, treatmentSummary := range treatmentSummarys {
  168. if item.PatientId == treatmentSummary.PatientId {
  169. scheduals[key].TreatmentSummary = treatmentSummary
  170. break
  171. }
  172. }
  173. for _, check := range dobulecheck {
  174. if item.PatientId == check.PatientId {
  175. scheduals[key].DoubleCheck = check
  176. break
  177. }
  178. }
  179. //// 监测
  180. //scheduals[key].VMMonitoringRecord = make([]models.VMMonitoringRecord, 0)
  181. //for _, moni := range monitor {
  182. // if item.PatientId == moni.PatientId {
  183. // scheduals[key].VMMonitoringRecord = append(scheduals[key].VMMonitoringRecord, moni)
  184. // }
  185. //}
  186. }
  187. //缓存数据
  188. scheduals_json, err := json.Marshal(&scheduals)
  189. if err == nil {
  190. redis.Set(key, scheduals_json, time.Second*60)
  191. }
  192. }
  193. //获取今日所有的处方开的耗材
  194. _, configs := service.FindXTHisProjectByOrgId(orgID)
  195. project := make([]*models.HisPrescriptionProjectTwo, 0)
  196. if configs.ID > 0 && configs.IsOpen == 1 {
  197. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  198. }
  199. //list, _ := service.GetZoneCountList(orgID, date.Unix())
  200. this.ServeSuccessJSON(map[string]interface{}{
  201. "scheduals": scheduals,
  202. "project": project,
  203. })
  204. }
  205. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  206. var dat []map[string]interface{}
  207. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  208. } else {
  209. }
  210. //获取今日所有的处方开的耗材
  211. _, configs := service.FindXTHisProjectByOrgId(orgID)
  212. project := make([]*models.HisPrescriptionProjectTwo, 0)
  213. if configs.ID > 0 && configs.IsOpen == 1 {
  214. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  215. }
  216. this.ServeSuccessJSON(map[string]interface{}{
  217. "scheduals": dat,
  218. "redis": "true",
  219. "date": schedualDate,
  220. "project": project,
  221. })
  222. }
  223. }
  224. // /m/api/waiting_scheduals [get]
  225. // @param date:string
  226. func (this *DialysisAPIController) WaitingScheduals() {
  227. schedualDate := this.GetString("date")
  228. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  229. if parseDateErr != nil && len(schedualDate) != 0 {
  230. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  231. return
  232. }
  233. adminInfo := this.GetMobileAdminUserInfo()
  234. orgID := adminInfo.Org.Id
  235. redis := service.RedisClient()
  236. defer redis.Close()
  237. // cur_date := time.Now().Format("2006-01-02")
  238. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  239. wait_scheduals, _ := redis.Get(key).Result()
  240. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  241. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  242. if err != nil {
  243. this.ErrorLog("获取排班信息失败:%v", err)
  244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  245. } else {
  246. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  247. for _, s := range scheduals {
  248. returnScheduals = append(returnScheduals, s)
  249. }
  250. if len(returnScheduals) > 0 {
  251. //缓存数据
  252. wait_scheduals_json, err := json.Marshal(scheduals)
  253. if err == nil {
  254. redis.Set(key, wait_scheduals_json, time.Second*30)
  255. }
  256. }
  257. this.ServeSuccessJSON(map[string]interface{}{
  258. "scheduals": scheduals,
  259. })
  260. }
  261. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  262. var dat []map[string]interface{}
  263. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  264. } else {
  265. }
  266. this.ServeSuccessJSON(map[string]interface{}{
  267. "scheduals": dat,
  268. "redis": "true",
  269. "date": schedualDate,
  270. })
  271. }
  272. }
  273. //else{
  274. // fmt.Println("33333333")
  275. //
  276. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  277. // if err != nil {
  278. // this.ErrorLog("获取排班信息失败:%v", err)
  279. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  280. // } else {
  281. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  282. // for _, s := range scheduals {
  283. //
  284. // returnScheduals = append(returnScheduals, s)
  285. // }
  286. //
  287. // this.ServeSuccessJSON(map[string]interface{}{
  288. // "scheduals": returnScheduals,
  289. // })
  290. // }
  291. //
  292. // }
  293. //if err == nil{
  294. //
  295. //
  296. //
  297. //
  298. //
  299. //}else{
  300. //}
  301. // /m/api/dialysis/record [get]
  302. // @param patient_id:int
  303. // @param date:string (yyyy-MM-dd)
  304. func (this *DialysisAPIController) DialysisRecord() {
  305. patientID, _ := this.GetInt64("patient_id")
  306. recordDateStr := this.GetString("date")
  307. if patientID <= 0 {
  308. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  309. return
  310. }
  311. if len(recordDateStr) == 0 {
  312. recordDateStr = time.Now().Format("2006-01-02")
  313. }
  314. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  315. if parseDateErr != nil {
  316. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  318. return
  319. }
  320. adminInfo := this.GetMobileAdminUserInfo()
  321. ch := make(chan struct{})
  322. count := 24 // count 表示活动的协程个数
  323. var patient models.Patients
  324. var receiverTreatmentAccess *models.ReceiveTreatmentAsses
  325. var predialysisEvaluation *models.PredialysisEvaluation
  326. var lastPredialysisEvaluation *models.PredialysisEvaluation
  327. var doctorAdvices []*models.DoctorAdvice
  328. var dialysisOrder *models.DialysisOrder
  329. var doubleCheck *models.DoubleCheck
  330. var monitorRecords []*models.MonitoringRecord
  331. var lastMonitorRecord *models.MonitoringRecord
  332. var assessmentAfterDislysis *models.AssessmentAfterDislysis
  333. var lastAssessmentAfterDislysis *models.AssessmentAfterDislysis
  334. var treatmentSummary *models.TreatmentSummary
  335. var dialysisPrescribe *models.DialysisPrescription
  336. var dialysisSolution *models.DialysisSolution
  337. var lastDialysisPrescribe *models.DialysisPrescription
  338. var systemDialysisPrescribe *models.SystemPrescription
  339. var is_project_open_config models.XtHisProjectConfig
  340. var projects []*models.HisPrescriptionProject
  341. var stockType []*models.GoodsTypeOne
  342. var prepare []*models.XtDialysisBeforePrepare
  343. var lastAssessment models.XtPatientVascularAccess
  344. var lastDryWeightDislysis *models.SgjPatientDryweight
  345. var gobalConfig models.GobalConfig
  346. var operators []*models.SgjUserAdminRoles
  347. // 先走redis,没有走数据库
  348. schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
  349. go func() {
  350. patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
  351. ch <- struct{}{}
  352. }()
  353. go func() {
  354. receiverTreatmentAccess, _ = service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  355. ch <- struct{}{}
  356. }()
  357. go func() {
  358. predialysisEvaluation, _ = service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  359. ch <- struct{}{}
  360. }()
  361. go func() {
  362. lastPredialysisEvaluation, _ = service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  363. ch <- struct{}{}
  364. }()
  365. go func() {
  366. doctorAdvices, _ = service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  367. ch <- struct{}{}
  368. }()
  369. go func() {
  370. dialysisOrder, _ = service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  371. ch <- struct{}{}
  372. }()
  373. go func() {
  374. doubleCheck, _ = service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  375. ch <- struct{}{}
  376. }()
  377. go func() {
  378. monitorRecords, _ = service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  379. ch <- struct{}{}
  380. }()
  381. go func() {
  382. lastMonitorRecord, _ = service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  383. ch <- struct{}{}
  384. }()
  385. go func() {
  386. assessmentAfterDislysis, _ = service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  387. ch <- struct{}{}
  388. }()
  389. go func() {
  390. lastAssessmentAfterDislysis, _ = service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  391. ch <- struct{}{}
  392. }()
  393. go func() {
  394. treatmentSummary, _ = service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  395. ch <- struct{}{}
  396. }()
  397. go func() {
  398. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  399. ch <- struct{}{}
  400. }()
  401. go func() {
  402. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  403. ch <- struct{}{}
  404. }()
  405. go func() {
  406. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminInfo.Org.Id, patientID, schedual.ModeId)
  407. ch <- struct{}{}
  408. }()
  409. go func() {
  410. systemDialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  411. ch <- struct{}{}
  412. }()
  413. go func() {
  414. // 先走redis,没有走数据库
  415. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  416. ch <- struct{}{}
  417. }()
  418. go func() {
  419. // 先走redis,没有走数据库
  420. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  421. ch <- struct{}{}
  422. }()
  423. go func() {
  424. // // 先走redis,没有走数据库
  425. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  426. ch <- struct{}{}
  427. }()
  428. go func() {
  429. // 先走redis,没有走数据库
  430. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  431. ch <- struct{}{}
  432. }()
  433. go func() {
  434. // //获取最后一次血管通路
  435. // 先走redis,没有走数据库
  436. lastAssessment, _ = service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
  437. ch <- struct{}{}
  438. }()
  439. go func() {
  440. // 先走redis,没有走数据库
  441. lastDryWeightDislysis, _ = service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  442. ch <- struct{}{}
  443. }()
  444. go func() {
  445. // 先走redis,没有走数据库
  446. _, gobalConfig = service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  447. ch <- struct{}{}
  448. }()
  449. go func() {
  450. // 先走redis,没有走数据库
  451. operators, _ = service.GetAllStarfEs(adminInfo.Org.Id)
  452. ch <- struct{}{}
  453. }()
  454. for range ch {
  455. // 每次从ch中接收数据,表明一个活动的协程结束
  456. count--
  457. // 当所有活动的协程都结束时,关闭管道
  458. if count == 0 {
  459. close(ch)
  460. }
  461. }
  462. prescribeOne, _ := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  463. _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
  464. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  465. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  466. temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
  467. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
  468. var team_projects []*models.HisPrescriptionProject
  469. //var index int64 = 0
  470. for _, item := range temp_team_projects {
  471. //组套里面非检验项目的
  472. if item.HisProject.CostClassify != 3 {
  473. projects = append(projects, item)
  474. }
  475. //组套里面检验项目的
  476. if item.HisProject.CostClassify == 3 {
  477. team_projects = append(team_projects, item)
  478. }
  479. }
  480. team_projects = RemoveRepeatedCheckRecod(team_projects)
  481. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  482. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  483. prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  484. var his_advices []*models.HisDoctorAdviceInfo
  485. if is_open_config.IsOpen == 1 {
  486. // 先走redis,没有走数据库
  487. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  488. }
  489. is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
  490. if is_advice_open.IsAdviceOpen == 1 {
  491. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  492. }
  493. lastOrder, _ := service.GetLastDilysisOrder(adminInfo.Org.Id, patientID, date.Unix())
  494. remind_config, _ := service.GetCheckRemindConfigById(adminInfo.Org.Id)
  495. var remind_lists []models.XtCheckRemind
  496. if remind_config.ID > 0 && remind_config.IsOpen == 1 {
  497. remind_lists, _ = service.GetAllInspectionRemind(adminInfo.Org.Id, patientID)
  498. }
  499. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminInfo.Org.Id)
  500. lastAssesmentBeforDialysis, _ := service.GetLastAssessmentBeforDialysis(patientID, adminInfo.Org.Id)
  501. dryWeightList, _ := service.GetPatientDryList(patientID, adminInfo.Org.Id)
  502. returnData := map[string]interface{}{
  503. "patient": patient,
  504. "schedual": schedual,
  505. "prescription": dialysisPrescribe,
  506. "solution": dialysisSolution,
  507. "last_prescription": lastDialysisPrescribe,
  508. "receiver_treatment_access": receiverTreatmentAccess,
  509. "predialysis_evaluation": predialysisEvaluation,
  510. "doctor_advices": doctorAdvices,
  511. "double_check": doubleCheck,
  512. "assessment_after_dislysis": assessmentAfterDislysis,
  513. "treatment_summary": treatmentSummary,
  514. "monitor_records": monitorRecords,
  515. "dialysis_order": dialysisOrder,
  516. "operators": operators,
  517. "last_predialysis_evaluation": lastPredialysisEvaluation,
  518. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  519. "last_monitor_record": lastMonitorRecord,
  520. "config": gobalConfig,
  521. "dry_weight": lastDryWeightDislysis,
  522. "system_prescription": systemDialysisPrescribe,
  523. "his_advices": his_advices,
  524. "is_open_config": is_open_config,
  525. "stockType": stockType,
  526. "prepare": prepare,
  527. "lastAssessment": lastAssessment,
  528. "prescribeOne": prescribeOne,
  529. "is_project_open_config": is_project_open_config,
  530. "project": projects,
  531. "team_projects": team_projects,
  532. "is_advice_open": is_advice_open,
  533. "prescription_open": prescriptionConfig.IsOpen,
  534. "lastOrder": lastOrder,
  535. "remind_lists": remind_lists,
  536. "lastDialysisPrescription": lastDialysisPrescription,
  537. "lastAssesmentBeforDialysis": lastAssesmentBeforDialysis,
  538. "dryWeightList": dryWeightList,
  539. }
  540. this.ServeSuccessJSON(returnData)
  541. }
  542. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  543. adminInfo := c.GetMobileAdminUserInfo()
  544. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  545. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  546. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  547. returnData := map[string]interface{}{
  548. "admin_users": adminUsers,
  549. "devices": devices,
  550. "device_numbers": device_numbers,
  551. }
  552. c.ServeSuccessJSON(returnData)
  553. }
  554. func (c *DialysisAPIController) PostAtreatmentInfo() {
  555. id, _ := c.GetInt64("patient", 0)
  556. recordDateStr := c.GetString("record_date")
  557. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  558. summaryContent := c.GetString("summaryContent")
  559. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  560. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  561. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  562. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  563. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  564. nursingRecord := c.GetString("nursing_record")
  565. fmt.Println("护理记录", nursingRecord)
  566. specialRecord := c.GetString("special_record")
  567. fmt.Println("特殊记录", specialRecord)
  568. adminUserInfo := c.GetMobileAdminUserInfo()
  569. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  570. checkStaffId = adminUserInfo.AdminUser.Id
  571. deboardNurseId = adminUserInfo.AdminUser.Id
  572. treatDoctor = adminUserInfo.AdminUser.Id
  573. if id <= 0 {
  574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  575. return
  576. }
  577. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  578. if patient.ID == 0 {
  579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  580. return
  581. }
  582. if len(recordDateStr) == 0 {
  583. recordDateStr = time.Now().Format("2006-01-02")
  584. }
  585. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  586. if parseDateErr != nil {
  587. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  589. return
  590. }
  591. summary := models.TreatmentSummary{
  592. UserOrgId: adminUserInfo.Org.Id,
  593. PatientId: id,
  594. AssessmentDate: recordDate.Unix(),
  595. Mission: propagandaAndEducationContent,
  596. DialysisSummary: summaryContent,
  597. SjNurse: changeMedicalNurseId,
  598. ZlNurse: treatNurseId,
  599. HdNurse: checkStaffId,
  600. XjNurse: deboardNurseId,
  601. ZlDoctor: treatDoctor,
  602. CreatedTime: time.Now().Unix(),
  603. Status: 1,
  604. NursingRecord: nursingRecord,
  605. SpecialRecord: specialRecord,
  606. }
  607. // 查询信息规挡的设置天数
  608. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  609. if infor.ID > 0 && infor.WeekDay > 0 {
  610. var cha_time int64
  611. timeNowStr := time.Now().Format("2006-01-02")
  612. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  613. //今日的日期减去设置的日期
  614. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  615. if cha_time >= recordDate.Unix() {
  616. //查询审核是否允许
  617. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 10)
  618. //申请状态不允许的情况 拒绝修改
  619. if infor.ApplicationStatus != 1 {
  620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  621. return
  622. }
  623. }
  624. }
  625. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  626. if treatmentSummary.ID == 0 { //新增
  627. summary.Creater = adminUserInfo.AdminUser.Id
  628. service.AddSigleSummaryRecord(&summary)
  629. finish := models.XtDialysisFinish{
  630. IsFinish: 1,
  631. UserOrgId: adminUserInfo.Org.Id,
  632. Status: 1,
  633. Ctime: time.Now().Unix(),
  634. Mtime: 0,
  635. Module: 10,
  636. RecordDate: recordDate.Unix(),
  637. Sourse: 1,
  638. PatientId: id,
  639. }
  640. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 10, id)
  641. if dialysisFinish.ID == 0 {
  642. service.CreateDialysisFinish(finish)
  643. }
  644. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  645. redis := service.RedisClient()
  646. //清空key 值
  647. redis.Set(key, "", time.Second)
  648. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  649. redis.Set(keyOne, "", time.Second)
  650. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  651. redis.Set(keyThree, "", time.Second)
  652. defer redis.Close()
  653. c.ServeSuccessJSON(map[string]interface{}{
  654. "summary": summary,
  655. })
  656. } else { //修改
  657. summary.Creater = treatmentSummary.Creater
  658. summary.CreatedTime = treatmentSummary.CreatedTime
  659. summary.Modifier = adminUserInfo.AdminUser.Id
  660. summary.ID = treatmentSummary.ID
  661. service.UpdateSummeRecord(&summary)
  662. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  663. redis := service.RedisClient()
  664. //清空key 值
  665. redis.Set(key, "", time.Second)
  666. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  667. redis.Set(keyOne, "", time.Second)
  668. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  669. redis.Set(keyThree, "", time.Second)
  670. defer redis.Close()
  671. c.ServeSuccessJSON(map[string]interface{}{
  672. "summary": summary,
  673. })
  674. }
  675. }
  676. func (c *DialysisAPIController) PostDoubleCheck() {
  677. id, _ := c.GetInt64("patient", 0)
  678. recordDateStr := c.GetString("record_date")
  679. checkTimeStr := c.GetString("check_time")
  680. firstCheckTimeStr := c.GetString("first_check_time")
  681. creater, _ := c.GetInt64("creater", 0)
  682. modifier, _ := c.GetInt64("modifier", 0)
  683. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  684. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  685. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  686. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  687. dialysis_item_desc := c.GetString("dialysis_item_desc")
  688. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  689. vascular_access_desc := c.GetString("vascular_access_desc")
  690. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  691. collator, _ := c.GetInt64("collator", 0)
  692. employee_number := c.GetString("employee_number")
  693. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  694. needle_batch_number := c.GetString("needle_batch_number")
  695. if id <= 0 {
  696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  697. return
  698. }
  699. adminUserInfo := c.GetMobileAdminUserInfo()
  700. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  701. if patient.ID == 0 {
  702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  703. return
  704. }
  705. if len(recordDateStr) == 0 {
  706. recordDateStr = time.Now().Format("2006-01-02")
  707. }
  708. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  709. if parseDateErr != nil {
  710. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  711. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  712. return
  713. }
  714. var checkDate int64
  715. if len(checkTimeStr) == 0 {
  716. checkDate = 0
  717. } else {
  718. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  719. checkDate = checkDateUnix.Unix()
  720. }
  721. var firstCheckDate int64
  722. if len(firstCheckTimeStr) == 0 {
  723. firstCheckDate = 0
  724. } else {
  725. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  726. firstCheckDate = firstCheckDateUnix.Unix()
  727. }
  728. if adminUserInfo.Org.Id == 10644 {
  729. list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
  730. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  731. if check.ID == 0 {
  732. if employee_number != list.JobNumber {
  733. c.ServeSuccessJSON(map[string]interface{}{
  734. "doubleCheck": check,
  735. "msg": "2",
  736. })
  737. return
  738. }
  739. }
  740. if check.ID > 0 {
  741. if employee_number != list.JobNumber {
  742. c.ServeSuccessJSON(map[string]interface{}{
  743. "doubleCheck": check,
  744. "msg": "2",
  745. })
  746. return
  747. }
  748. }
  749. }
  750. doubleCheck := models.DoubleCheck{
  751. UserOrgId: adminUserInfo.Org.Id,
  752. PatientId: id,
  753. DialysisItemCheck: dialysis_item_check,
  754. DialysisParameterCheck: dialysis_parameter_check,
  755. VascularAccessVerification: vascular_access_verification,
  756. PipelineConnectionCheck: pipeline_connection_check,
  757. DialysisItemDesc: dialysis_item_desc,
  758. DialysisParameterDesc: dialysis_parameter_desc,
  759. VascularAccessDesc: vascular_access_desc,
  760. PipelineConnectionDesc: pipeline_connection_desc,
  761. Collator: collator,
  762. Status: 1,
  763. CreatedTime: time.Now().Unix(),
  764. CheckDate: recordDate.Unix(),
  765. UpdatedTime: time.Now().Unix(),
  766. EmployeeNumber: employee_number,
  767. DialyzerBatchNumber: dialyzer_batch_number,
  768. NeedleBatchNumber: needle_batch_number,
  769. }
  770. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  771. if check.ID == 0 { //新增
  772. doubleCheck.FirstCheckTime = firstCheckDate
  773. doubleCheck.CheckTime = checkDate
  774. doubleCheck.Creater = creater
  775. doubleCheck.Modifier = modifier
  776. if adminUserInfo.Org.Id == 10340 {
  777. order, _ := service.GetDialysisOrder(recordDate.Unix(), id, adminUserInfo.Org.Id)
  778. doubleCheck.Creater = order.StartNurse
  779. }
  780. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  781. //查询未核对的医嘱
  782. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  783. for _, advice := range doctorList {
  784. if advice.ExecutionStaff == modifier {
  785. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  786. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  787. return
  788. }
  789. }
  790. }
  791. // 查询信息规挡的设置天数
  792. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  793. if infor.ID > 0 && infor.WeekDay > 0 {
  794. var cha_time int64
  795. timeNowStr := time.Now().Format("2006-01-02")
  796. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  797. //今日的日期减去设置的日期
  798. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  799. if cha_time >= recordDate.Unix() {
  800. //查询审核是否允许
  801. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  802. //申请状态不允许的情况 拒绝修改
  803. if infor.ApplicationStatus != 1 {
  804. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  805. return
  806. }
  807. }
  808. }
  809. err := service.AddSigleDoubleCheck(&doubleCheck)
  810. finish := models.XtDialysisFinish{
  811. IsFinish: 1,
  812. UserOrgId: adminUserInfo.Org.Id,
  813. Status: 1,
  814. Ctime: time.Now().Unix(),
  815. Mtime: 0,
  816. Module: 5,
  817. RecordDate: recordDate.Unix(),
  818. Sourse: 1,
  819. PatientId: id,
  820. }
  821. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 5, id)
  822. if dialysisFinish.ID == 0 {
  823. service.CreateDialysisFinish(finish)
  824. }
  825. //针对长沙南雅
  826. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  827. //查询未核对的医嘱
  828. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  829. if len(doctorList) > 0 && modifier > 0 {
  830. for _, advice := range doctorList {
  831. service.UpdateDoctorAdviceList(advice.ID, modifier)
  832. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  833. redis := service.RedisClient()
  834. //清空key 值
  835. redis.Set(key, "", time.Second)
  836. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  837. redis.Set(keyTwo, "", time.Second)
  838. theTime := time.Now()
  839. recordDate := theTime.Format("2006-01-02")
  840. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  841. redis.Set(keyFour, "", time.Second)
  842. defer redis.Close()
  843. }
  844. }
  845. }
  846. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  847. redis := service.RedisClient()
  848. //清空key 值
  849. redis.Set(key, "", time.Second)
  850. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  851. redis.Set(keyOne, "", time.Second)
  852. defer redis.Close()
  853. if err == nil {
  854. c.ServeSuccessJSON(map[string]interface{}{
  855. "doubleCheck": &doubleCheck,
  856. })
  857. }
  858. } else { //修改
  859. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  860. if infor.ID > 0 {
  861. var cha_time int64
  862. timeNowStr := time.Now().Format("2006-01-02")
  863. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  864. //今日的日期减去设置的日期
  865. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  866. if cha_time >= recordDate.Unix() {
  867. //查询审核是否允许
  868. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  869. //申请状态不允许的情况 拒绝修改
  870. if infor.ApplicationStatus != 1 {
  871. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  872. return
  873. }
  874. }
  875. }
  876. doubleCheck.FirstCheckTime = firstCheckDate
  877. doubleCheck.CheckTime = checkDate
  878. doubleCheck.Creater = creater
  879. doubleCheck.Modifier = modifier
  880. doubleCheck.CreatedTime = check.CreatedTime
  881. doubleCheck.ID = check.ID
  882. doubleCheck.EmployeeNumber = employee_number
  883. doubleCheck.NeedleBatchNumber = needle_batch_number
  884. doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
  885. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  886. //查询未核对的医嘱
  887. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  888. for _, advice := range doctorList {
  889. if advice.ExecutionStaff == modifier {
  890. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  891. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  892. return
  893. }
  894. }
  895. }
  896. err := service.UpdateDoubleCheck(&doubleCheck)
  897. //针对长沙南雅
  898. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  899. //查询未核对的医嘱
  900. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  901. if len(doctorList) > 0 && modifier > 0 {
  902. for _, advice := range doctorList {
  903. service.UpdateDoctorAdviceList(advice.ID, modifier)
  904. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  905. redis := service.RedisClient()
  906. //清空key 值
  907. redis.Set(key, "", time.Second)
  908. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  909. redis.Set(keyTwo, "", time.Second)
  910. theTime := time.Now()
  911. recordDate := theTime.Format("2006-01-02")
  912. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  913. redis.Set(keyFour, "", time.Second)
  914. defer redis.Close()
  915. }
  916. }
  917. }
  918. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  919. redis := service.RedisClient()
  920. //清空key 值
  921. redis.Set(key, "", time.Second)
  922. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  923. redis.Set(keyOne, "", time.Second)
  924. defer redis.Close()
  925. if err == nil {
  926. c.ServeSuccessJSON(map[string]interface{}{
  927. "doubleCheck": &doubleCheck,
  928. "msg": "1",
  929. })
  930. }
  931. }
  932. }
  933. func (c *DialysisAPIController) PostAcceptsAssessment() {
  934. id, _ := c.GetInt64("patient", 0)
  935. recordDateStr := c.GetString("record_date")
  936. way, _ := c.GetInt64("way", 0)
  937. consciousness, _ := c.GetInt64("consciousness", 0)
  938. appetite, _ := c.GetInt64("appetite", 0)
  939. condition, _ := c.GetInt64("condition", 0)
  940. posture, _ := c.GetInt64("posture")
  941. sick_condition, _ := c.GetInt64("sick_condition", 0)
  942. danger_level, _ := c.GetInt64("danger_level", 0)
  943. intake, _ := c.GetInt64("intake", 0)
  944. nutrition, _ := c.GetInt64("nutrition", 0)
  945. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  946. psychological_assessment_other := c.GetString("psychological_assessment_other")
  947. score := c.GetString("score")
  948. sick_condition_other := c.GetString("sick_condition_other")
  949. //precaution, _ := c.GetInt64("precaution", 0)
  950. precaution := c.GetString("precaution")
  951. precaution_other := c.GetString("precaution_other")
  952. psychological_other := c.GetString("psychological_other")
  953. admission_number := c.GetString("admission_number")
  954. tumble, _ := c.GetInt64("tumble")
  955. diacrisis := c.GetString("diacrisis")
  956. his_department := c.GetString("his_department")
  957. his_bed := c.GetString("his_bed")
  958. if id <= 0 {
  959. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  960. return
  961. }
  962. adminUserInfo := c.GetMobileAdminUserInfo()
  963. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  964. if patient.ID == 0 {
  965. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  966. return
  967. }
  968. //now := time.Now()
  969. //year, month, day := now.Date()
  970. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  971. //todayTimeStamp := today_time.Unix()
  972. if len(recordDateStr) == 0 {
  973. recordDateStr = time.Now().Format("2006-01-02")
  974. }
  975. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  976. if parseDateErr != nil {
  977. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  978. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  979. return
  980. }
  981. // 查询信息规挡的设置天数
  982. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  983. if infor.ID > 0 && infor.WeekDay > 0 {
  984. var cha_time int64
  985. timeNowStr := time.Now().Format("2006-01-02")
  986. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  987. //今日的日期减去设置的日期
  988. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  989. if cha_time >= recordDate.Unix() {
  990. //查询审核是否允许
  991. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  992. //申请状态不允许的情况 拒绝修改
  993. if infor.ApplicationStatus != 1 {
  994. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  995. return
  996. }
  997. }
  998. }
  999. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1000. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1001. UserOrgId: adminUserInfo.Org.Id,
  1002. PatientId: id,
  1003. RecordDate: recordDate.Unix(),
  1004. Way: way,
  1005. Consciousness: consciousness,
  1006. Appetite: appetite,
  1007. Condition: condition,
  1008. SickCondition: sick_condition,
  1009. DangerLevel: danger_level,
  1010. Intake: intake,
  1011. Nutrition: nutrition,
  1012. PsychologicalAssessment: psychological_assessment,
  1013. PsychologicalAssessmentOther: psychological_assessment_other,
  1014. SickConditionOther: sick_condition_other,
  1015. Posture: posture,
  1016. CreatedTime: time.Now().Unix(),
  1017. UpdateTime: time.Now().Unix(),
  1018. Status: 1,
  1019. Score: score,
  1020. Precaution: precaution,
  1021. PrecautionOther: precaution_other,
  1022. PsychologicalOther: psychological_other,
  1023. AdmissionNumber: admission_number,
  1024. Tumble: tumble,
  1025. Diacrisis: diacrisis,
  1026. HisBed: his_bed,
  1027. HisDepartment: his_department,
  1028. }
  1029. if receiveTreatment.ID == 0 { //新增
  1030. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1031. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1032. finish := models.XtDialysisFinish{
  1033. IsFinish: 1,
  1034. UserOrgId: adminUserInfo.Org.Id,
  1035. Status: 1,
  1036. Ctime: time.Now().Unix(),
  1037. Mtime: 0,
  1038. Module: 2,
  1039. RecordDate: recordDate.Unix(),
  1040. Sourse: 1,
  1041. PatientId: id,
  1042. }
  1043. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1044. if dialysisFinish.ID == 0 {
  1045. service.CreateDialysisFinish(finish)
  1046. }
  1047. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1048. redis := service.RedisClient()
  1049. defer redis.Close()
  1050. //清空key 值
  1051. redis.Set(key, "", time.Second)
  1052. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1053. redis.Set(keyOne, "", time.Second)
  1054. if err == nil {
  1055. c.ServeSuccessJSON(map[string]interface{}{
  1056. "receiveTreatmentAsses": receiveTreatmentAsses,
  1057. })
  1058. }
  1059. } else { //修改
  1060. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1061. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1062. // if getPermissionErr != nil {
  1063. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1064. // return
  1065. // } else if headNursePermission == nil {
  1066. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1067. // return
  1068. // }
  1069. //}
  1070. // 查询信息规挡的设置天数
  1071. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1072. if infor.ID > 0 && infor.WeekDay > 0 {
  1073. var cha_time int64
  1074. timeNowStr := time.Now().Format("2006-01-02")
  1075. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1076. //今日的日期减去设置的日期
  1077. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1078. if cha_time >= recordDate.Unix() {
  1079. //查询审核是否允许
  1080. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1081. //申请状态不允许的情况 拒绝修改
  1082. if infor.ApplicationStatus != 1 {
  1083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1084. return
  1085. }
  1086. }
  1087. }
  1088. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1089. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1090. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1091. receiveTreatmentAsses.ID = receiveTreatment.ID
  1092. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1093. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1094. redis := service.RedisClient()
  1095. defer redis.Close()
  1096. //清空key 值
  1097. redis.Set(key, "", time.Second)
  1098. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1099. redis.Set(keyOne, "", time.Second)
  1100. if err == nil {
  1101. c.ServeSuccessJSON(map[string]interface{}{
  1102. "receiveTreatmentAsses": receiveTreatmentAsses,
  1103. })
  1104. }
  1105. }
  1106. }
  1107. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1108. id, _ := c.GetInt64("patient", 0)
  1109. recordDateStr := c.GetString("record_date")
  1110. weightAfter, _ := c.GetFloat("weight_after", 0)
  1111. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1112. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1113. fmt.Println("weight_loss", weightReduce)
  1114. temperature, _ := c.GetFloat("temperature", 0)
  1115. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1116. breathing_rate := c.GetString("breathing_rate")
  1117. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1118. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1119. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1120. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1121. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1122. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1123. cruor := c.GetString("cruor")
  1124. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1125. internalFistula := c.GetString("internal_fistula")
  1126. catheter := c.GetString("catheter")
  1127. complications := c.GetString("complication")
  1128. remark := c.GetString("remark")
  1129. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1130. dialysis_intakes := c.GetString("dialysis_intakes")
  1131. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1132. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1133. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1134. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1135. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1136. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1137. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1138. patientGose, _ := c.GetInt64("patient_gose", 0)
  1139. inpatientDepartment := c.GetString("inpatient_department")
  1140. observationContent := c.GetString("observation_content")
  1141. observationContentOther := c.GetString("observation_content_other")
  1142. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1143. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1144. in_advance_reason := c.GetString("in_advance_reason")
  1145. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1146. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1147. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1148. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1149. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1150. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1151. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1152. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1153. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1154. is_eat, _ := c.GetInt64("is_eat", 0)
  1155. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1156. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1157. channels, _ := c.GetInt64("channel", 0)
  1158. return_blood, _ := c.GetInt64("return_blood", 0)
  1159. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1160. dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1161. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1162. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1163. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1164. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1165. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1166. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1167. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1168. setting_pressure := c.GetString("setting_pressure")
  1169. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1170. diastolic_pressure := c.GetString("diastolic_pressure")
  1171. other_complication := c.GetString("other_complication")
  1172. ktv := c.GetString("ktv")
  1173. urr := c.GetString("urr")
  1174. hypertenison, _ := c.GetInt64("hypertenison")
  1175. hypopiesia, _ := c.GetInt64("hypopiesia")
  1176. leave_office_method, _ := c.GetInt64("leave_office_method")
  1177. lapse, _ := c.GetInt64("lapse")
  1178. consciousness, _ := c.GetInt64("consciousness")
  1179. fallrisk, _ := c.GetInt64("fallrisk")
  1180. machine_run := c.GetString("machine_run")
  1181. after_urea := c.GetString("after_urea")
  1182. pip_coagulation := c.GetString("pip_coagulation")
  1183. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1184. transfusion_volume := c.GetString("transfusion_volume")
  1185. last_after_weight := c.GetString("last_after_weight")
  1186. displace_liqui_value := c.GetString("displace_liqui_value")
  1187. if id <= 0 {
  1188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1189. return
  1190. }
  1191. adminUserInfo := c.GetMobileAdminUserInfo()
  1192. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1193. if patient.ID == 0 {
  1194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1195. return
  1196. }
  1197. if len(recordDateStr) == 0 {
  1198. recordDateStr = time.Now().Format("2006-01-02")
  1199. }
  1200. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1201. fmt.Println("parseDateErr", parseDateErr)
  1202. if parseDateErr != nil {
  1203. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1205. return
  1206. }
  1207. //now := time.Now()
  1208. //year, month, day := now.Date()
  1209. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1210. //todayTimeStamp := today_time.Unix()
  1211. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1212. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1213. UserOrgId: adminUserInfo.Org.Id,
  1214. PatientId: id,
  1215. AssessmentDate: recordDate.Unix(),
  1216. Temperature: temperature,
  1217. PulseFrequency: pulse_frequency,
  1218. BreathingRate: breathing_rate,
  1219. SystolicBloodPressure: systolic_blood_pressure,
  1220. DiastolicBloodPressure: diastolic_blood_pressure,
  1221. ActualUltrafiltration: actual_ultrafiltration,
  1222. ActualDisplacement: actual_displacement,
  1223. ActualTreatmentHour: actualtreatHour,
  1224. ActualTreatmentMinute: actualtreatmin,
  1225. WeightAfter: weightAfter,
  1226. AdditionalWeight: additionalWeight,
  1227. WeightLoss: weightReduce,
  1228. Cruor: cruor,
  1229. SymptomAfterDialysis: symptomsAfterDialysi,
  1230. InternalFistula: internalFistula,
  1231. Catheter: catheter,
  1232. Complication: complications,
  1233. DialysisIntakes: dialysateVolume,
  1234. CreatedTime: time.Now().Unix(),
  1235. UpdatedTime: time.Now().Unix(),
  1236. Status: 1,
  1237. Remark: remark,
  1238. BloodAccessPartId: blood_access_part_id,
  1239. BloodAccessPartOperaId: blood_access_part_opera_id,
  1240. DialysisIntakesUnit: dialysis_intakes_unit,
  1241. PuncturePointOozingBlood: puncturePointOozingBlood,
  1242. PuncturePointHaematoma: puncturePointHaematoma,
  1243. InternalFistulaTremorAc: internalFistulaTremorAc,
  1244. PatientGose: patientGose,
  1245. InpatientDepartment: inpatientDepartment,
  1246. ObservationContent: observationContent,
  1247. ObservationContentOther: observationContentOther,
  1248. DialysisProcess: dialysis_process,
  1249. InAdvanceMinute: in_advance_minute,
  1250. InAdvanceReason: in_advance_reason,
  1251. HemostasisMinute: hemostasis_minute,
  1252. HemostasisOpera: hemostasis_opera,
  1253. TremorNoise: tremor_noise,
  1254. DisequilibriumSyndrome: disequilibrium_syndrome,
  1255. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1256. ArterialTube: arterial_tube,
  1257. IntravenousTube: intravenous_tube,
  1258. Dialyzer: dialyzer,
  1259. InAdvanceReasonOther: in_advance_reason_other,
  1260. IsEat: is_eat,
  1261. CvcA: cvc_a,
  1262. CvcV: cvc_v,
  1263. Channel: channels,
  1264. ReturnBlood: return_blood,
  1265. RehydrationVolume: rehydration_volume,
  1266. DialysisDuring: dialysis_during,
  1267. StrokeVolume: stroke_volume,
  1268. BloodFlow: blood_flow,
  1269. SealingFluidDispose: sealing_fluid_dispose,
  1270. SealingFluidSpecial: sealing_fluid_special,
  1271. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1272. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1273. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1274. SettingPressure: setting_pressure,
  1275. DiastolicPressure: diastolic_pressure,
  1276. OtherComplication: other_complication,
  1277. Ktv: ktv,
  1278. Urr: urr,
  1279. Hypopiesia: hypopiesia,
  1280. Hypertenison: hypertenison,
  1281. Lapse: lapse,
  1282. LeaveOfficeMethod: leave_office_method,
  1283. Consciousness: consciousness,
  1284. Fallrisk: fallrisk,
  1285. MachineRun: machine_run,
  1286. AfterUrea: after_urea,
  1287. PipCoagulation: pip_coagulation,
  1288. AccumulatedBloodVolume: accumulated_blood_volume,
  1289. TransfusionVolume: transfusion_volume,
  1290. LastAfterWeight: last_after_weight,
  1291. DisplaceLiquiValue: displace_liqui_value,
  1292. }
  1293. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1294. // 查询信息规挡的设置天数
  1295. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1296. if infor.ID > 0 && infor.WeekDay > 0 {
  1297. var cha_time int64
  1298. timeNowStr := time.Now().Format("2006-01-02")
  1299. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1300. //今日的日期减去设置的日期
  1301. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1302. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1303. if cha_time >= recordDate.Unix() {
  1304. //查询审核是否允许
  1305. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1306. //申请状态不允许的情况 拒绝修改
  1307. if infor.ApplicationStatus != 1 {
  1308. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1309. return
  1310. }
  1311. }
  1312. }
  1313. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1314. if assessmentAfter.ID == 0 { //新增
  1315. if appRole.UserType == 2 || appRole.UserType == 1 {
  1316. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1317. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1318. } else {
  1319. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1320. }
  1321. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1322. if assessmentAfterDislysis.UserOrgId != 10340 {
  1323. if assessmentAfterDislysis.WeightAfter == 0 {
  1324. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1325. }
  1326. }
  1327. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1328. //记录日志
  1329. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1330. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1331. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1332. PatientId: assessmentAfterDislysis.PatientId,
  1333. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1334. Status: 1,
  1335. ErrLog: string(byterequest),
  1336. AdminUserId: adminUserInfo.AdminUser.Id,
  1337. Ctime: 0,
  1338. Mtime: 0,
  1339. Source: "手机端保存透后评估",
  1340. }
  1341. service.CreateAfterDialysisLog(afterDialysisLog)
  1342. finish := models.XtDialysisFinish{
  1343. IsFinish: 1,
  1344. UserOrgId: adminUserInfo.Org.Id,
  1345. Status: 1,
  1346. Ctime: time.Now().Unix(),
  1347. Mtime: 0,
  1348. Module: 9,
  1349. RecordDate: recordDate.Unix(),
  1350. Sourse: 1,
  1351. PatientId: id,
  1352. }
  1353. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1354. if dialysisFinish.ID == 0 {
  1355. service.CreateDialysisFinish(finish)
  1356. }
  1357. redis := service.RedisClient()
  1358. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1359. redis.Set(keyTwo, "", time.Second)
  1360. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1361. //清空key 值
  1362. redis.Set(key, "", time.Second)
  1363. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1364. redis.Set(keyOne, "", time.Second)
  1365. defer redis.Close()
  1366. if err == nil {
  1367. c.ServeSuccessJSON(map[string]interface{}{
  1368. "assessmentAfterDislysis": assessmentAfterDislysis,
  1369. })
  1370. }
  1371. return
  1372. } else { //修改
  1373. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1374. if infor.ID > 0 && infor.WeekDay > 0 {
  1375. var cha_time int64
  1376. timeNowStr := time.Now().Format("2006-01-02")
  1377. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1378. //今日的日期减去设置的日期
  1379. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1380. if cha_time >= recordDate.Unix() {
  1381. //查询审核是否允许
  1382. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1383. //申请状态不允许的情况 拒绝修改
  1384. if infor.ApplicationStatus != 1 {
  1385. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1386. return
  1387. }
  1388. }
  1389. }
  1390. if appRole.UserType == 2 || appRole.UserType == 1 {
  1391. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1392. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1393. } else {
  1394. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1395. if assessmentAfterDislysis.Creater == 0 {
  1396. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1397. }
  1398. }
  1399. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1400. assessmentAfterDislysis.ID = assessmentAfter.ID
  1401. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1402. if assessmentAfterDislysis.UserOrgId != 10340 {
  1403. if assessmentAfterDislysis.WeightAfter == 0 {
  1404. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1405. }
  1406. }
  1407. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1408. //记录日志
  1409. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1410. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1411. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1412. PatientId: assessmentAfterDislysis.PatientId,
  1413. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1414. Status: 1,
  1415. ErrLog: string(byterequest),
  1416. AdminUserId: adminUserInfo.AdminUser.Id,
  1417. Ctime: time.Now().Unix(),
  1418. Mtime: 0,
  1419. Source: "手机端修改保存透后评估",
  1420. }
  1421. service.CreateAfterDialysisLog(afterDialysisLog)
  1422. redis := service.RedisClient()
  1423. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1424. redis.Set(keyTwo, "", time.Second)
  1425. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1426. //清空key 值
  1427. redis.Set(key, "", time.Second)
  1428. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1429. redis.Set(keyOne, "", time.Second)
  1430. if err == nil {
  1431. c.ServeSuccessJSON(map[string]interface{}{
  1432. "assessmentAfterDislysis": assessmentAfterDislysis,
  1433. })
  1434. return
  1435. }
  1436. }
  1437. return
  1438. }
  1439. func (c *DialysisAPIController) PostDialysisPrescription() {
  1440. id, _ := c.GetInt64("patient", 0)
  1441. recordDateStr := c.GetString("record_date")
  1442. if id <= 0 {
  1443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1444. return
  1445. }
  1446. adminUserInfo := c.GetMobileAdminUserInfo()
  1447. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1448. if patient.ID == 0 {
  1449. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1450. return
  1451. }
  1452. if len(recordDateStr) == 0 {
  1453. recordDateStr = time.Now().Format("2006-01-02")
  1454. }
  1455. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1456. if parseDateErr != nil {
  1457. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1459. return
  1460. }
  1461. mode_id, _ := c.GetInt64("mode_id", 0)
  1462. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1463. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1464. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1465. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1466. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1467. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1468. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1469. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1470. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1471. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1472. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1473. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1474. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1475. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1476. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1477. kalium, _ := c.GetFloat("kalium", 0)
  1478. sodium, _ := c.GetFloat("sodium", 0)
  1479. calcium, _ := c.GetFloat("calcium", 0)
  1480. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1481. glucose, _ := c.GetFloat("glucose", 0)
  1482. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1483. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1484. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1485. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1486. conductivity, _ := c.GetFloat("conductivity", 0)
  1487. remark := c.GetString("remark")
  1488. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1489. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1490. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1491. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1492. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1493. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1494. special_medicine_other := c.GetString("special_medicine_other")
  1495. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1496. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1497. blood_access, _ := c.GetInt64("blood_access", 0)
  1498. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1499. body_fluid_other := c.GetString("body_fluid_other")
  1500. niprocart, _ := c.GetInt64("niprocart", 0)
  1501. jms, _ := c.GetInt64("jms", 0)
  1502. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1503. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1504. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1505. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1506. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1507. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1508. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1509. injector, _ := c.GetInt64("injector", 0)
  1510. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1511. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1512. safe_package, _ := c.GetInt64("package", 0)
  1513. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1514. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1515. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1516. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1517. blood := c.GetString("blood")
  1518. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1519. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1520. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1521. displace_speed := c.GetString("displace_speed")
  1522. illness, _ := c.GetInt64("illness")
  1523. amylaceum := c.GetString("amylaceum")
  1524. single_time := c.GetString("single_time")
  1525. single_water := c.GetString("single_water")
  1526. replacement_flow := c.GetString("replacement_flow")
  1527. plasma_separator := c.GetString("plasma_separator")
  1528. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1529. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1530. oxygen_flow := c.GetString("oxygen_flow")
  1531. oxygen_time := c.GetString("oxygen_time")
  1532. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1533. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1534. puncture_needle := c.GetString("puncture_needle")
  1535. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1536. epo := c.GetString("epo")
  1537. epo_count, _ := c.GetFloat("epo_count", 0)
  1538. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1539. admin_user_id, _ := c.GetInt64("admin_user_id")
  1540. is_water := c.GetString("is_water")
  1541. var is_war int64
  1542. if is_water == "是" {
  1543. is_war = 1
  1544. }
  1545. if is_water == "否" {
  1546. is_war = 2
  1547. }
  1548. if is_water == "请选择" {
  1549. is_war = 0
  1550. }
  1551. drhy_water := c.GetString("drhy_water")
  1552. dry_water_hour := c.GetString("dry_water_hour")
  1553. water_machine := c.GetString("water_machine")
  1554. add_amount, _ := c.GetFloat("add_amount")
  1555. reduce_amount, _ := c.GetFloat("reduce_amount")
  1556. dialysis_remark := c.GetString("dialysis_remark")
  1557. prescribing_number, _ := c.GetFloat("prescribing_number")
  1558. prescription_sodium := c.GetString("prescription_sodium")
  1559. start_sodium := c.GetString("start_sodium")
  1560. sodium_curve := c.GetString("sodium_curve")
  1561. treatment_remark := c.GetString("treatment_remark")
  1562. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1563. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1564. prescription_water, _ := c.GetFloat("prescription_water")
  1565. dialysis_strainer := c.GetString("dialysis_strainer")
  1566. chaptalization := c.GetString("chaptalization")
  1567. washing_time := c.GetString("washing_time")
  1568. warsh_count := c.GetString("warsh_count")
  1569. blood_access_part_id := c.GetString("blood_access_part_id")
  1570. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1571. dialyzate := c.GetString("dialyzate")
  1572. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1573. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1574. //
  1575. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1576. // if appRole.UserType == 3 {
  1577. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1578. // if getPermissionErr != nil {
  1579. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1580. // return
  1581. // } else if headNursePermission == nil {
  1582. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1583. // return
  1584. // }
  1585. // }
  1586. //}
  1587. // 查询信息规挡的设置天数
  1588. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1589. if infor.ID > 0 && infor.WeekDay > 0 {
  1590. var cha_time int64
  1591. timeNowStr := time.Now().Format("2006-01-02")
  1592. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1593. //今日的日期减去设置的日期
  1594. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1595. if cha_time >= recordDate.Unix() {
  1596. //查询审核是否允许
  1597. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1598. //申请状态不允许的情况 拒绝修改
  1599. if infor.ApplicationStatus != 1 {
  1600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1601. return
  1602. }
  1603. }
  1604. }
  1605. if mode_id > 0 {
  1606. var str string
  1607. //查找该机构用的是什么透析器
  1608. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1609. if filedConfig.ID > 0 {
  1610. str = dialyzerPerfusionApparatus
  1611. } else {
  1612. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1613. }
  1614. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1615. }
  1616. //TODO 需要根据角色去判断
  1617. prescription := models.DialysisPrescription{
  1618. UserOrgId: adminUserInfo.Org.Id,
  1619. PatientId: id,
  1620. RecordDate: recordDate.Unix(),
  1621. ModeId: mode_id,
  1622. DialysisDuration: dialysis_duration,
  1623. Dialyzer: dialyzer,
  1624. PerfusionApparatus: perfusion_apparatus,
  1625. BloodFlowVolume: blood_flow_volume,
  1626. DewaterAmount: dewater_amount,
  1627. DisplaceLiqui: displace_liqui,
  1628. ReplacementWay: replacement_way,
  1629. Anticoagulant: anticoagulant,
  1630. AnticoagulantShouji: anticoagulant_shouji,
  1631. AnticoagulantWeichi: anticoagulant_weichi,
  1632. AnticoagulantZongliang: anticoagulant_zongliang,
  1633. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1634. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1635. Kalium: kalium,
  1636. Sodium: sodium,
  1637. Calcium: calcium,
  1638. Bicarbonate: bicarbonate,
  1639. Glucose: glucose,
  1640. // DryWeight: dry_weight,
  1641. DialysateFlow: dialysate_flow,
  1642. DialysateTemperature: dialysate_temperature,
  1643. // PrescriptionDoctor: prescription_doctor,
  1644. ReplacementTotal: replacement_total,
  1645. Conductivity: conductivity,
  1646. Remark: remark,
  1647. Status: 1,
  1648. CreatedTime: time.Now().Unix(),
  1649. UpdatedTime: time.Now().Unix(),
  1650. DialysisDurationMinute: dialysisDurationMinute,
  1651. DialysisDurationHour: dialysisDurationHour,
  1652. TargetUltrafiltration: targetUltrafiltration,
  1653. DialysateFormulation: dialysateFormulation,
  1654. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1655. BodyFluid: body_fluid,
  1656. SpecialMedicine: special_medicine,
  1657. SpecialMedicineOther: special_medicine_other,
  1658. DisplaceLiquiPart: displace_liqui_part,
  1659. DisplaceLiquiValue: displace_liqui_value,
  1660. BloodAccess: blood_access,
  1661. Ultrafiltration: ultrafiltration,
  1662. BodyFluidOther: body_fluid_other,
  1663. Niprocart: niprocart,
  1664. Jms: jms,
  1665. FistulaNeedleSet: fistula_needle_set,
  1666. FistulaNeedleSet16: fistula_needle_set_16,
  1667. Hemoperfusion: hemoperfusion,
  1668. DialyserSterilised: dialyser_sterilised,
  1669. Filtryzer: filtryzer,
  1670. Dialyzers: dialyzers,
  1671. Injector: injector,
  1672. Bloodlines: bloodlines,
  1673. TubingHemodialysis: tubing_hemodialysis,
  1674. Package: safe_package,
  1675. ALiquid: a_liquid,
  1676. TargetKtv: target_ktv,
  1677. PreImpulse: pre_impulse,
  1678. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1679. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1680. Blood: blood,
  1681. DialysisDialyszers: dialysis_dialyszers,
  1682. DialysisIrrigation: dialysis_irrigation,
  1683. AntioxidantCommodityName: antioxidant_commodity_name,
  1684. DisplaceSpeed: displace_speed,
  1685. Illness: illness,
  1686. Amylaceum: amylaceum,
  1687. SingleTime: single_time,
  1688. SingleWater: single_water,
  1689. ReplacementFlow: replacement_flow,
  1690. PlasmaSeparator: plasma_separator,
  1691. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1692. OxygenUptake: oxygen_uptake,
  1693. OxygenFlow: oxygen_flow,
  1694. OxygenTime: oxygen_time,
  1695. HemodialysisPipelines: hemodialysis_pipelines,
  1696. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1697. PunctureNeedle: puncture_needle,
  1698. PunctureNeedleCount: puncture_needle_count,
  1699. Epo: epo,
  1700. EpoCount: epo_count,
  1701. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1702. AdminUserId: admin_user_id,
  1703. IsWater: is_war,
  1704. DrhyWater: drhy_water,
  1705. DryWaterHour: dry_water_hour,
  1706. WaterMachine: water_machine,
  1707. AddAmount: add_amount,
  1708. ReduceAmount: reduce_amount,
  1709. DialysisRemark: dialysis_remark,
  1710. PrescribingNumber: prescribing_number,
  1711. StartSodium: start_sodium,
  1712. SodiumCurve: sodium_curve,
  1713. TreatmentRemark: treatment_remark,
  1714. PrescriptionSodium: prescription_sodium,
  1715. DialysisFluidFlow: dialysis_fluid_flow,
  1716. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1717. PrescriptionWater: prescription_water,
  1718. DialysisStrainer: dialysis_strainer,
  1719. Chaptalization: chaptalization,
  1720. WashingTime: washing_time,
  1721. WarshCount: warsh_count,
  1722. BloodAccessPartId: blood_access_part_id,
  1723. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1724. Dialyzate: dialyzate,
  1725. }
  1726. //查询最近透析准备表里是否存在 透析器 灌流器
  1727. //
  1728. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1729. //
  1730. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1731. //
  1732. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1733. //if len(mation)>0{
  1734. // for _, item := range splitStr {
  1735. // for _,it := range mation{
  1736. // if(item == it.SpecificationName){
  1737. //
  1738. // //查询最近一次的透析器
  1739. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1740. //
  1741. // if errcode == gorm.ErrRecordNotFound{
  1742. // //插入数据
  1743. // prepare := models.DialysisBeforePrepare{
  1744. // UserOrgId: adminUserInfo.Org.Id,
  1745. // PatientId: id,
  1746. // RecordDate: recordDate.Unix(),
  1747. // GoodTypeId: it.GoodTypeId,
  1748. // GoodId: it.ID,
  1749. // Count: 1,
  1750. // Ctime: time.Now().Unix(),
  1751. // Creater: adminUserInfo.AdminUser.Id,
  1752. // Status:1,
  1753. //
  1754. // }
  1755. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1756. // fmt.Println("",errcode)
  1757. // }
  1758. // }
  1759. // }
  1760. //
  1761. // }
  1762. //
  1763. // for _, item := range splitIrrigation {
  1764. // for _,it := range mation{
  1765. // if(item == it.SpecificationName){
  1766. // //查询最近一次的透析器
  1767. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1768. // if errcode == gorm.ErrRecordNotFound{
  1769. // //插入数据
  1770. // prepare := models.DialysisBeforePrepare{
  1771. // UserOrgId: adminUserInfo.Org.Id,
  1772. // PatientId: id,
  1773. // RecordDate: recordDate.Unix(),
  1774. // GoodTypeId: it.GoodTypeId,
  1775. // GoodId: it.ID,
  1776. // Count: 1,
  1777. // Ctime: time.Now().Unix(),
  1778. // Creater: adminUserInfo.AdminUser.Id,
  1779. // Status:1,
  1780. //
  1781. // }
  1782. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1783. // fmt.Println(errcode)
  1784. // }
  1785. // }
  1786. // }
  1787. // }
  1788. //}
  1789. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1790. if dialysisPrescription.ID == 0 { //新增
  1791. if appRole.UserType == 2 || appRole.UserType == 1 {
  1792. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1793. }
  1794. prescription.Creater = adminUserInfo.AdminUser.Id
  1795. //针对河间咸得
  1796. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  1797. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  1798. prescription.DisplaceLiquiPart = 0
  1799. prescription.DisplaceLiquiValue = 0
  1800. }
  1801. }
  1802. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  1803. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  1804. }
  1805. err := service.AddSigleRecord(&prescription)
  1806. //记录日志
  1807. byterequest, _ := json.Marshal(prescription)
  1808. prescriptionLog := models.XtDialysisPrescriptionLog{
  1809. UserOrgId: prescription.UserOrgId,
  1810. Ctime: time.Now().Unix(),
  1811. Mtime: 0,
  1812. ErrLog: string(byterequest),
  1813. AdminUserId: adminUserInfo.AdminUser.Id,
  1814. RecordDate: prescription.RecordDate,
  1815. PatientId: prescription.PatientId,
  1816. Source: "手机端新增保存处方",
  1817. Status: 1,
  1818. }
  1819. service.CreatePrescriptionLog(prescriptionLog)
  1820. finish := models.XtDialysisFinish{
  1821. IsFinish: 1,
  1822. UserOrgId: adminUserInfo.Org.Id,
  1823. Status: 1,
  1824. Ctime: time.Now().Unix(),
  1825. Mtime: 0,
  1826. Module: 1,
  1827. RecordDate: recordDate.Unix(),
  1828. Sourse: 1,
  1829. PatientId: id,
  1830. }
  1831. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  1832. if dialysisFinish.ID == 0 {
  1833. service.CreateDialysisFinish(finish)
  1834. }
  1835. //长沙南雅医院,自动生成抗凝剂的临时处方
  1836. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  1837. if prescribing_number == 0 {
  1838. prescribing_number = 1
  1839. }
  1840. if prescribing_number == 0 && id == 14682 {
  1841. prescribing_number = 2
  1842. }
  1843. if prescribing_number == 0 && id == 18560 {
  1844. prescribing_number = 2
  1845. }
  1846. advice := models.DoctorAdvice{
  1847. UserOrgId: adminUserInfo.Org.Id,
  1848. PatientId: id,
  1849. GroupNo: 0,
  1850. AdviceType: 2,
  1851. RecordDate: recordDate.Unix(),
  1852. AdviceDate: recordDate.Unix(),
  1853. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  1854. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  1855. AdviceDesc: "",
  1856. ReminderDate: 0,
  1857. SingleDose: anticoagulant_zongliang,
  1858. SingleDoseUnit: "iu",
  1859. DrugSpec: 0,
  1860. DrugSpecUnit: "",
  1861. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  1862. PrescribingNumberUnit: "支",
  1863. DeliveryWay: "静脉注射",
  1864. ExecutionFrequency: "上机前",
  1865. AdviceDoctor: 0,
  1866. Status: 1,
  1867. CreatedTime: time.Now().Unix(),
  1868. UpdatedTime: time.Now().Unix(),
  1869. IsPrescription: 1,
  1870. ExecutionState: 2,
  1871. StopState: 2,
  1872. IsSettle: 2,
  1873. }
  1874. // 查询排班信息
  1875. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1876. if schedulePatient.ID > 0 {
  1877. if schedulePatient.ScheduleType == 1 {
  1878. advice.StartTime = recordDate.Unix() + 6.5*60*60
  1879. }
  1880. if schedulePatient.ScheduleType == 2 {
  1881. advice.StartTime = recordDate.Unix() + 9*60*60
  1882. }
  1883. }
  1884. // 抗凝剂名称
  1885. switch anticoagulant {
  1886. case 1:
  1887. advice.AdviceName = "无肝素"
  1888. break
  1889. case 2:
  1890. advice.AdviceName = "普通肝素"
  1891. break
  1892. case 3:
  1893. advice.AdviceName = "低分子肝素"
  1894. break
  1895. case 4:
  1896. advice.AdviceName = "阿加曲班"
  1897. break
  1898. case 5:
  1899. advice.AdviceName = "枸橼酸钠"
  1900. break
  1901. case 6:
  1902. advice.AdviceName = "低分子肝素钙"
  1903. break
  1904. case 7:
  1905. advice.AdviceName = "低分子肝素钠"
  1906. break
  1907. case 8:
  1908. advice.AdviceName = "依诺肝素"
  1909. break
  1910. case 9:
  1911. advice.AdviceName = "达肝素"
  1912. break
  1913. case 10:
  1914. advice.AdviceName = "体外抗凝"
  1915. break
  1916. case 11:
  1917. advice.AdviceName = "那曲肝素"
  1918. break
  1919. case 12:
  1920. advice.AdviceName = "无抗凝剂"
  1921. break
  1922. }
  1923. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  1924. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  1925. advice.AdviceDoctor = appRole.AdminUserId
  1926. }
  1927. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  1928. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  1929. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  1930. advice.AdviceName = "低分子肝素钠注射液"
  1931. // 修改患者临时医嘱里的抗凝剂医嘱
  1932. advice.ID = advicePrescription.ID
  1933. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  1934. } else {
  1935. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  1936. advice.AdviceName = "低分子肝素钠注射液"
  1937. // 新增患者临时医嘱里的抗凝剂医嘱
  1938. service.CreateDoctorAdvice(&advice)
  1939. }
  1940. }
  1941. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  1942. redis := service.RedisClient()
  1943. defer redis.Close()
  1944. //清空key 值
  1945. redis.Set(key, "", time.Second)
  1946. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  1947. redis.Set(keyOne, "", time.Second)
  1948. }
  1949. //获取key,清空redis
  1950. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1951. redis := service.RedisClient()
  1952. //清空key 值
  1953. redis.Set(key, "", time.Second)
  1954. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1955. //清空key 值
  1956. redis.Set(keyOne, "", time.Second)
  1957. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1958. //清空key 值
  1959. redis.Set(keyTwo, "", time.Second)
  1960. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1961. redis.Set(keySix, "", time.Second)
  1962. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1963. redis.Set(keySeven, "", time.Second)
  1964. if err == nil {
  1965. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  1966. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  1967. //清空key 值
  1968. redis.Set(keyThree, "", time.Second)
  1969. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  1970. //清空key 值
  1971. redis.Set(keyFour, "", time.Second)
  1972. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  1973. redis.Set(keyFive, "", time.Second)
  1974. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1975. redis.Set(keySix, "", time.Second)
  1976. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1977. redis.Set(keySeven, "", time.Second)
  1978. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1979. //清空key 值
  1980. redis.Set(keyOne, "", time.Second)
  1981. if updateErr != nil {
  1982. utils.ErrorLog("%v", updateErr)
  1983. }
  1984. defer redis.Close()
  1985. c.ServeSuccessJSON(map[string]interface{}{
  1986. "prescription": prescription,
  1987. })
  1988. }
  1989. } else { //修改
  1990. //if mode_id > 0 {
  1991. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  1992. //}
  1993. //if template.TemplateId == 1 {
  1994. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  1995. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1996. // if getPermissionErr != nil {
  1997. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1998. // return
  1999. // } else if headNursePermission == nil {
  2000. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  2001. // return
  2002. // }
  2003. // }
  2004. //}
  2005. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2006. prescription.Modifier = adminUserInfo.AdminUser.Id
  2007. if appRole.UserType == 2 || appRole.UserType == 1 {
  2008. prescription_doctor := adminUserInfo.AdminUser.Id
  2009. prescription.PrescriptionDoctor = prescription_doctor
  2010. } else {
  2011. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2012. }
  2013. if dialysisPrescription.Creater == 0 { //体重称
  2014. prescription.Creater = adminUserInfo.AdminUser.Id
  2015. } else {
  2016. prescription.Creater = dialysisPrescription.Creater
  2017. if adminUserInfo.Org.Id == 9882 {
  2018. if appRole.UserType == 2 || appRole.UserType == 1 {
  2019. prescription_doctor := adminUserInfo.AdminUser.Id
  2020. prescription.PrescriptionDoctor = prescription_doctor
  2021. prescription.Creater = prescription_doctor
  2022. }
  2023. }
  2024. }
  2025. prescription.ID = dialysisPrescription.ID
  2026. service.UpDateDialysisPrescription(&prescription)
  2027. //记录日志
  2028. byterequest, _ := json.Marshal(prescription)
  2029. prescriptionLog := models.XtDialysisPrescriptionLog{
  2030. UserOrgId: prescription.UserOrgId,
  2031. Ctime: time.Now().Unix(),
  2032. Mtime: 0,
  2033. ErrLog: string(byterequest),
  2034. AdminUserId: adminUserInfo.AdminUser.Id,
  2035. RecordDate: prescription.RecordDate,
  2036. PatientId: prescription.PatientId,
  2037. Source: "手机端修改处方",
  2038. Status: 1,
  2039. }
  2040. service.CreatePrescriptionLog(prescriptionLog)
  2041. finish := models.XtDialysisFinish{
  2042. IsFinish: 1,
  2043. UserOrgId: adminUserInfo.Org.Id,
  2044. Status: 1,
  2045. Ctime: time.Now().Unix(),
  2046. Mtime: 0,
  2047. Module: 1,
  2048. RecordDate: recordDate.Unix(),
  2049. Sourse: 1,
  2050. PatientId: id,
  2051. }
  2052. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2053. if dialysisFinish.ID == 0 {
  2054. service.CreateDialysisFinish(finish)
  2055. }
  2056. //修改处方
  2057. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2058. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2059. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2060. if advicePrescription.ID > 0 {
  2061. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2062. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2063. redis := service.RedisClient()
  2064. defer redis.Close()
  2065. //清空key 值
  2066. redis.Set(key, "", time.Second)
  2067. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2068. redis.Set(keyOne, "", time.Second)
  2069. }
  2070. }
  2071. //获取key,清空redis
  2072. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2073. redis := service.RedisClient()
  2074. //清空key 值
  2075. redis.Set(key, "", time.Second)
  2076. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2077. //清空key 值
  2078. redis.Set(keyOne, "", time.Second)
  2079. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2080. redis.Set(keySix, "", time.Second)
  2081. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2082. redis.Set(keySeven, "", time.Second)
  2083. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2084. keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2085. //清空key 值
  2086. redis.Set(keyTwoOne, "", time.Second)
  2087. defer redis.Close()
  2088. if updateErr != nil {
  2089. utils.ErrorLog("%v", updateErr)
  2090. }
  2091. c.ServeSuccessJSON(map[string]interface{}{
  2092. "prescription": prescription,
  2093. })
  2094. }
  2095. }
  2096. func (c *DialysisAPIController) Finish() {
  2097. id, _ := c.GetInt64("patient", 0)
  2098. recordDateStr := c.GetString("record_date")
  2099. nurseID, _ := c.GetInt64("nurse")
  2100. end_time := c.GetString("end_time")
  2101. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2102. internal_fistula := c.GetString("blood_access_internal_fistula")
  2103. catheter := c.GetString("catheter")
  2104. cruor := c.GetString("cruor")
  2105. mission := c.GetString("mission")
  2106. condenser := c.GetString("condenser")
  2107. if id <= 0 || nurseID <= 0 {
  2108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2109. return
  2110. }
  2111. adminUserInfo := c.GetMobileAdminUserInfo()
  2112. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2113. if patient.ID == 0 {
  2114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2115. return
  2116. }
  2117. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2118. if getNurseErr != nil {
  2119. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2121. return
  2122. } else if nurse == nil {
  2123. c.ErrorLog("护士不存在")
  2124. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2125. return
  2126. }
  2127. if len(recordDateStr) == 0 {
  2128. recordDateStr = time.Now().Format("2006-01-02")
  2129. }
  2130. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2131. if parseDateErr != nil {
  2132. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2134. return
  2135. }
  2136. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2137. if parseEndDateErr != nil {
  2138. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2140. return
  2141. }
  2142. // 查询信息规挡的设置天数
  2143. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2144. if infor.ID > 0 && infor.WeekDay > 0 {
  2145. var cha_time int64
  2146. timeNowStr := time.Now().Format("2006-01-02")
  2147. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2148. //今日的日期减去设置的日期
  2149. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2150. if cha_time >= recordDate.Unix() {
  2151. //查询审核是否允许
  2152. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2153. //申请状态不允许的情况 拒绝修改
  2154. if infor.ApplicationStatus != 1 {
  2155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2156. return
  2157. }
  2158. }
  2159. }
  2160. //now := time.Now()
  2161. //year, month, day := now.Date()
  2162. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2163. //todayTimeStamp := today_time.Unix()
  2164. // 获取当天的第一条透析纪录
  2165. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2166. if getMonitorRecordsErr != nil {
  2167. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2169. return
  2170. }
  2171. // 获取当前的最后一条透析纪录
  2172. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2173. if getMonitorRecordsErr != nil {
  2174. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2175. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2176. return
  2177. }
  2178. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2179. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2180. if getAADErr != nil {
  2181. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2183. return
  2184. }
  2185. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2186. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2187. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2188. if assessmentAfterDislysis != nil {
  2189. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2190. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2191. } else {
  2192. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2193. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2194. tempassessmentAfterDislysis.Status = 1
  2195. tempassessmentAfterDislysis.PatientId = id
  2196. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2197. }
  2198. //长沙南雅
  2199. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2200. //获取最后一条透析处方数据
  2201. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2202. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2203. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2204. }
  2205. if dialysisOrder.Stage == 1 {
  2206. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2207. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2208. fmt.Println(value)
  2209. a, b := math.Modf(value)
  2210. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2211. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2212. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2213. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2214. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2215. }
  2216. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2217. //var num1 int64
  2218. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2219. //fmt.Println(num1)
  2220. //sub := float64(num1 / 3600)
  2221. //fmt.Println(sub)
  2222. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2223. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2224. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2225. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2226. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2227. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2228. if adminUserInfo.Org.Id != 10375 {
  2229. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2230. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2231. }
  2232. if adminUserInfo.Org.Id != 10445 {
  2233. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2234. }
  2235. //北方营口医院
  2236. if adminUserInfo.Org.Id == 10445 {
  2237. //获取最后一条透析处方数据
  2238. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2239. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2240. } else {
  2241. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2242. }
  2243. //新化博翔
  2244. if adminUserInfo.Org.Id == 10447 {
  2245. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2246. }
  2247. //阳春
  2248. if adminUserInfo.Org.Id == 10485 {
  2249. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2250. }
  2251. if adminUserInfo.Org.Id == 10551 {
  2252. //获取最后一条透析处方数据
  2253. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2254. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2255. }
  2256. if adminUserInfo.Org.Id == 10580 {
  2257. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2258. }
  2259. if adminUserInfo.Org.Id == 10612 {
  2260. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2261. }
  2262. }
  2263. 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 {
  2264. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2265. if evaluation.SystolicBloodPressure == 0 {
  2266. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2267. pre := models.PredialysisEvaluation{
  2268. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2269. }
  2270. fmt.Println("prew", pre)
  2271. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2272. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2273. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2274. redis := service.RedisClient()
  2275. redis.Set(key, "", time.Second)
  2276. redis.Set(keyOne, "", time.Second)
  2277. defer redis.Close()
  2278. fmt.Println(getNurseErr)
  2279. }
  2280. if evaluation.DiastolicBloodPressure == 0 {
  2281. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2282. pres := models.PredialysisEvaluation{
  2283. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2284. }
  2285. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2286. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2287. redis := service.RedisClient()
  2288. redis.Set(key, "", time.Second)
  2289. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2290. redis.Set(keyOne, "", time.Second)
  2291. defer redis.Close()
  2292. fmt.Println(getNurseErr)
  2293. }
  2294. if evaluation.PulseFrequency == 0 {
  2295. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2296. press := models.PredialysisEvaluation{
  2297. PulseFrequency: evaluation.PulseFrequency,
  2298. }
  2299. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2300. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2301. redis := service.RedisClient()
  2302. redis.Set(key, "", time.Second)
  2303. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2304. redis.Set(keyOne, "", time.Second)
  2305. defer redis.Close()
  2306. fmt.Println(getNurseErr)
  2307. }
  2308. if evaluation.Temperature == 0 {
  2309. evaluation.Temperature = fmonitorRecords.Temperature
  2310. press := models.PredialysisEvaluation{
  2311. Temperature: evaluation.Temperature,
  2312. }
  2313. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2314. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2315. redis := service.RedisClient()
  2316. redis.Set(key, "", time.Second)
  2317. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2318. redis.Set(keyOne, "", time.Second)
  2319. defer redis.Close()
  2320. fmt.Println(getNurseErr)
  2321. }
  2322. }
  2323. if adminUserInfo.Org.Id == 9583 {
  2324. //获取透析处方的最后一条数据
  2325. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2326. if diaerr != nil {
  2327. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2328. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2329. return
  2330. }
  2331. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2332. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2333. }
  2334. }
  2335. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2336. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2337. }
  2338. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2339. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2340. }
  2341. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2342. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2343. }
  2344. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2345. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2346. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2347. }
  2348. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2349. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2350. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2351. }
  2352. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2353. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2354. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2355. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2356. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2357. }
  2358. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2359. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2360. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2361. }
  2362. if lastAssessmentAfterDislysis != nil {
  2363. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2364. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2365. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2366. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2367. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2368. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2369. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2370. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2371. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2372. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2373. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2374. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2375. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2376. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2377. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2378. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2379. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2380. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2381. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2382. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2383. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2384. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2385. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2386. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2387. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2388. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2389. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2390. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2391. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2392. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2393. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2394. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2395. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2396. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2397. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2398. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2399. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2400. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2401. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2402. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2403. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2404. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2405. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2406. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2407. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2408. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2409. tempassessmentAfterDislysis.Ktv = lastAssessmentAfterDislysis.Ktv
  2410. tempassessmentAfterDislysis.Urr = lastAssessmentAfterDislysis.Urr
  2411. if tempassessmentAfterDislysis.PatientId == 18695 {
  2412. tempassessmentAfterDislysis.ActualDisplacement = 0
  2413. }
  2414. if adminUserInfo.Org.Id != 10375 {
  2415. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2416. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2417. }
  2418. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2419. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2420. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2421. }
  2422. }
  2423. finish := models.XtDialysisFinish{
  2424. IsFinish: 1,
  2425. UserOrgId: adminUserInfo.Org.Id,
  2426. Status: 1,
  2427. Ctime: time.Now().Unix(),
  2428. Mtime: 0,
  2429. Module: 9,
  2430. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2431. Sourse: 1,
  2432. PatientId: tempassessmentAfterDislysis.PatientId,
  2433. }
  2434. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2435. if dialysisFinish.ID == 0 {
  2436. service.CreateDialysisFinish(finish)
  2437. }
  2438. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2439. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2440. redis := service.RedisClient()
  2441. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2442. redis.Set(keyOne, "", time.Second)
  2443. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2444. redis.Set(keyTwo, "", time.Second)
  2445. defer redis.Close()
  2446. //清空key 值
  2447. redis.Set(key, "", time.Second)
  2448. if err != nil {
  2449. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2450. return
  2451. }
  2452. if dialysisOrder == nil {
  2453. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2454. return
  2455. }
  2456. if dialysisOrder.Stage == 2 {
  2457. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2458. return
  2459. }
  2460. if dialysisOrder.Stage == 1 {
  2461. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2462. finish := models.XtDialysisFinish{
  2463. IsFinish: 1,
  2464. UserOrgId: adminUserInfo.Org.Id,
  2465. Status: 1,
  2466. Ctime: time.Now().Unix(),
  2467. Mtime: 0,
  2468. Module: 8,
  2469. RecordDate: recordDate.Unix(),
  2470. Sourse: 1,
  2471. PatientId: id,
  2472. }
  2473. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2474. if dialysisFinish.ID == 0 {
  2475. service.CreateDialysisFinish(finish)
  2476. }
  2477. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2478. redis := service.RedisClient()
  2479. defer redis.Close()
  2480. //清空key 值
  2481. redis.Set(key, "", time.Second)
  2482. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2483. redis.Set(keyOne, "", time.Second)
  2484. //结束时候透析次数加1
  2485. service.UpdateSolutionByPatientId(id)
  2486. //下机完自动消毒,针对长沙南雅
  2487. if dialysisOrder.Stage == 1 {
  2488. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9538 || adminUserInfo.Org.Id == 10121 || adminUserInfo.Org.Id == 10612 {
  2489. //根据床位号获取设备型号
  2490. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2491. //查询使用消毒最后一条消毒记录
  2492. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2493. fmt.Println("err", err)
  2494. if err == gorm.ErrRecordNotFound {
  2495. //查找排班
  2496. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2497. //查询改设备是否有消毒计划
  2498. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2499. //根据床位号获取设备id
  2500. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2501. //查询病人信息
  2502. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2503. var con = ""
  2504. if patients.IsInfectious == 0 {
  2505. con = ""
  2506. }
  2507. if patients.IsInfectious == 1 {
  2508. con = "无"
  2509. }
  2510. if patients.IsInfectious == 2 {
  2511. con = "有"
  2512. }
  2513. if errcode == nil {
  2514. var end_time int64
  2515. end_time = endDate.Unix() + plan.DisinfecTime*60
  2516. //新增消毒
  2517. information := models.DeviceInformation{
  2518. Date: dialysisOrder.DialysisDate,
  2519. Zone: dialysisOrder.ZoneId,
  2520. Class: dialysisOrder.SchedualType,
  2521. BedNumber: dialysisOrder.BedID,
  2522. PatientId: dialysisOrder.PatientId,
  2523. DialysisMode: scheduleByPatient.ModeId,
  2524. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2525. Disinfection: 1,
  2526. DialysisConcentration: 1,
  2527. DisinfectionStatus: 1,
  2528. Move: 1,
  2529. UserOrgId: dialysisOrder.UserOrgId,
  2530. DisinfectType: plan.Way,
  2531. DisinfectantType: plan.MachineDisinfectant,
  2532. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2533. Disinfectant: plan.Disinfectant,
  2534. Ctime: time.Now().Unix(),
  2535. Status: 1,
  2536. SignName: nurseID,
  2537. EquimentId: addmacher.ID,
  2538. DisinfectionResidue: 2,
  2539. Bed: addmacher.BedNumber,
  2540. StartTime: dialysisOrder.StartTime,
  2541. EndTime: dialysisOrder.EndTime,
  2542. Contagion: con,
  2543. WeightLoss: 0,
  2544. Hyperfiltratio: 0,
  2545. DialysisHour: "",
  2546. MachineRun: 1,
  2547. DisinfecStartime: endDate.Unix(),
  2548. DisinfecEndtime: end_time,
  2549. }
  2550. err := service.CreateInformationTwo(&information)
  2551. fmt.Println("报错", err)
  2552. }
  2553. }
  2554. }
  2555. }
  2556. dialysisOrder.Stage = 2
  2557. dialysisOrder.FinishNurse = nurseID
  2558. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2559. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2560. dialysisOrder.EndTime = endDate.Unix()
  2561. // 长沙南雅需求
  2562. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2563. //获取最后1条监测的数据
  2564. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2565. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2566. var accumulatedBloodVolume float64
  2567. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2568. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2569. fmt.Println(err)
  2570. // 查询未执行的医嘱
  2571. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2572. for _, item := range doctorAdvice {
  2573. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2574. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2575. redis := service.RedisClient()
  2576. //清空key 值
  2577. redis.Set(key, "", time.Second)
  2578. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2579. redis.Set(keyTwo, "", time.Second)
  2580. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2581. redis.Set(keyThree, "", time.Second)
  2582. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2583. theTime := toTime.Format("2006-01-02")
  2584. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2585. redis.Set(keyFour, "", time.Second)
  2586. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2587. redis.Set(keyFive, "", time.Second)
  2588. defer redis.Close()
  2589. }
  2590. }
  2591. go func() {
  2592. ssoDomain := beego.AppConfig.String("call_domain")
  2593. api := ssoDomain + "/index/downpatient"
  2594. values := make(url.Values)
  2595. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2596. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2597. values.Set("patient_id", strconv.FormatInt(id, 10))
  2598. http.PostForm(api, values)
  2599. }()
  2600. if err == nil {
  2601. c.ServeSuccessJSON(map[string]interface{}{
  2602. "dialysisOrder": dialysisOrder,
  2603. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2604. })
  2605. } else {
  2606. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2607. }
  2608. }
  2609. }
  2610. func (c *DialysisAPIController) GetAllZone() {
  2611. adminUserInfo := c.GetMobileAdminUserInfo()
  2612. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  2613. if err == nil {
  2614. c.ServeSuccessJSON(map[string]interface{}{
  2615. "zone": zone,
  2616. })
  2617. }
  2618. }
  2619. func (c *DialysisAPIController) GetSchedualPatientsList() {
  2620. adminUserInfo := c.GetMobileAdminUserInfo()
  2621. page, _ := c.GetInt64("page", 1)
  2622. limit, _ := c.GetInt64("limit", 10)
  2623. schedulType, _ := c.GetInt64("schedul_type", 0)
  2624. startTime, _ := c.GetInt64("schedul_time", 0)
  2625. partitionType, _ := c.GetInt64("partition_type", 0)
  2626. keywords := c.GetString("keywords")
  2627. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  2628. if err == nil {
  2629. c.ServeSuccessJSON(map[string]interface{}{
  2630. "schedule": dialysisSchedule,
  2631. })
  2632. }
  2633. return
  2634. }
  2635. // /m/api/dialysis/start [post]
  2636. // @param patient_id:int
  2637. // @param record_date:string 排班时间 (yyyy-mm-dd)
  2638. // @param nurse:int 上机护士
  2639. // @param bed:int 床位号
  2640. func (this *DialysisAPIController) StartDialysis() {
  2641. patientID, _ := this.GetInt64("patient_id")
  2642. recordDateStr := this.GetString("record_date")
  2643. nurseID, _ := this.GetInt64("start_nurse")
  2644. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2645. blood_drawing, _ := this.GetInt64("blood_drawing")
  2646. schedual_type, _ := this.GetInt64("schedual_type")
  2647. bedID, _ := this.GetInt64("bed")
  2648. start_time := this.GetString("start_time")
  2649. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  2650. change_nurse, _ := this.GetInt64("change_nurse")
  2651. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  2652. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  2653. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  2654. puncture_needle := this.GetString("puncture_needle")
  2655. puncture_way := this.GetString("puncture_way")
  2656. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  2657. dialysis_irrigation := this.GetString("dialysis_irrigation")
  2658. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  2659. zone_id, _ := this.GetInt64("zone_id")
  2660. elecsign := this.GetString("url")
  2661. nuclein_date_str := this.GetString("nuclein_date_str")
  2662. schedule_remark := this.GetString("schedule_remark")
  2663. order_remark := this.GetString("order_remark")
  2664. catheter_operation := this.GetString("catheter_operation")
  2665. blood_flow_volume := this.GetString("blood_flow_volume")
  2666. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  2667. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2668. return
  2669. }
  2670. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2671. if parseStartDateErr != nil {
  2672. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2673. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2674. return
  2675. }
  2676. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2677. if parseErr != nil {
  2678. this.ErrorLog("时间解析失败:%v", parseErr)
  2679. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2680. return
  2681. }
  2682. adminUserInfo := this.GetMobileAdminUserInfo()
  2683. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  2684. if getPatientErr != nil {
  2685. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2686. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2687. return
  2688. } else if patient == nil {
  2689. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2690. return
  2691. }
  2692. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2693. if getNurseErr != nil {
  2694. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2695. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2696. return
  2697. } else if nurse == nil {
  2698. this.ErrorLog("护士不存在")
  2699. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2700. return
  2701. }
  2702. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2703. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2704. if getDeviceNumberErr != nil {
  2705. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2706. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2707. return
  2708. } else if deviceNumber == nil {
  2709. this.ErrorLog("床位号不存在")
  2710. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2711. return
  2712. }
  2713. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2714. if getRecordErr != nil {
  2715. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  2716. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2717. return
  2718. } else if dialysisRecord != nil {
  2719. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  2720. return
  2721. }
  2722. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2723. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2724. timeLayout := "2006-01-02 15:04:05"
  2725. loc, _ := time.LoadLocation("Local")
  2726. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2727. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2728. schedulestartTime := theStartTime.Unix()
  2729. scheduleendTime := theEndTime.Unix()
  2730. var theNucleinDate int64
  2731. timeLayoutOne := "2006-01-02"
  2732. if len(nuclein_date_str) > 0 {
  2733. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  2734. if err != nil {
  2735. utils.ErrorLog(err.Error())
  2736. }
  2737. theNucleinDate = theTime.Unix()
  2738. }
  2739. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2740. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2741. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  2742. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2743. //查询该床位是否有人用了
  2744. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2745. if err == gorm.ErrRecordNotFound { //空床位
  2746. // 修改了床位逻辑
  2747. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2748. if daySchedule.ID > 0 {
  2749. daySchedule.PartitionId = deviceNumber.ZoneID
  2750. daySchedule.BedId = bedID
  2751. daySchedule.ScheduleType = schedual_type
  2752. daySchedule.UpdatedTime = time.Now().Unix()
  2753. xtSchedule := models.Schedule{
  2754. PartitionId: deviceNumber.ZoneID,
  2755. BedId: bedID,
  2756. ScheduleType: schedual_type,
  2757. UpdatedTime: time.Now().Unix(),
  2758. }
  2759. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2760. if err != nil {
  2761. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2762. return
  2763. }
  2764. }
  2765. } else if err == nil {
  2766. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2767. if order.ID > 0 { //该机位被其他人占用了
  2768. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2769. return
  2770. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  2771. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2772. if daySchedule.ID > 0 {
  2773. err := service.UpdateScheduleTwo(daySchedule, schedule)
  2774. if err != nil {
  2775. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2776. return
  2777. }
  2778. }
  2779. }
  2780. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2781. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2782. return
  2783. }
  2784. //else if order.ID == 0 { //该床位没被占用
  2785. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2786. // if daySchedule.ID > 0 {
  2787. // //daySchedule.PartitionId = deviceNumber.ZoneID
  2788. // //daySchedule.BedId = bedID
  2789. // //daySchedule.ScheduleType = schedual_type
  2790. // //daySchedule.UpdatedTime = time.Now().Unix()
  2791. // //err := service.UpdateSchedule(&daySchedule)
  2792. // xtSchedule := models.Schedule{
  2793. // PartitionId: deviceNumber.ZoneID,
  2794. // BedId: bedID,
  2795. // ScheduleType: schedual_type,
  2796. // UpdatedTime: time.Now().Unix(),
  2797. // }
  2798. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2799. // if err != nil {
  2800. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2801. // return
  2802. // }
  2803. // }
  2804. //}
  2805. //}
  2806. } else if err != nil {
  2807. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2808. return
  2809. }
  2810. // 查询信息规挡的设置天数
  2811. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2812. if infor.ID > 0 && infor.WeekDay > 0 {
  2813. var cha_time int64
  2814. timeNowStr := time.Now().Format("2006-01-02")
  2815. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2816. //今日的日期减去设置的日期
  2817. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2818. if cha_time >= recordDate.Unix() {
  2819. //查询审核是否允许
  2820. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  2821. //申请状态不允许的情况 拒绝修改
  2822. if infor.ApplicationStatus != 1 {
  2823. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2824. return
  2825. }
  2826. }
  2827. }
  2828. dialysisRecord = &models.DialysisOrder{
  2829. DialysisDate: recordDate.Unix(),
  2830. UserOrgId: adminUserInfo.Org.Id,
  2831. PatientId: patientID,
  2832. Stage: 1,
  2833. BedID: bedID,
  2834. StartNurse: nurseID,
  2835. Status: 1,
  2836. StartTime: startDate.Unix(),
  2837. CreatedTime: time.Now().Unix(),
  2838. UpdatedTime: time.Now().Unix(),
  2839. PunctureNurse: puncture_nurse,
  2840. Creator: adminUserInfo.AdminUser.Id,
  2841. Modifier: adminUserInfo.AdminUser.Id,
  2842. SchedualType: schedual_type,
  2843. WashpipeNurse: washpipe_nurse,
  2844. ChangeNurse: change_nurse,
  2845. DifficultPunctureNurse: difficult_puncture_nurse,
  2846. NewFistulaNurse: new_fistula_nurse,
  2847. ZoneId: zone_id,
  2848. QualityNurseId: quality_nurse_id,
  2849. PunctureNeedle: puncture_needle,
  2850. PunctureWay: puncture_way,
  2851. DialysisIrrigation: dialysis_irrigation,
  2852. DialysisDialyszers: dialysis_dialyszers,
  2853. BloodAccessId: blood_access_id,
  2854. Url: elecsign,
  2855. NucleinDate: theNucleinDate,
  2856. ScheduleRemark: schedule_remark,
  2857. OrderRemark: order_remark,
  2858. CatheterOperation: catheter_operation,
  2859. BloodFlowVolume: blood_flow_volume,
  2860. BloodDrawing: blood_drawing,
  2861. }
  2862. //查询该床位是否有人用了
  2863. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2864. if errorscode == gorm.ErrRecordNotFound {
  2865. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  2866. finish := models.XtDialysisFinish{
  2867. IsFinish: 1,
  2868. UserOrgId: adminUserInfo.Org.Id,
  2869. Status: 1,
  2870. Ctime: time.Now().Unix(),
  2871. Mtime: 0,
  2872. Module: 6,
  2873. RecordDate: schedulestartTime,
  2874. Sourse: 1,
  2875. PatientId: patientID,
  2876. }
  2877. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  2878. if dialysisFinish.ID == 0 {
  2879. service.CreateDialysisFinish(finish)
  2880. }
  2881. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  2882. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  2883. //统计该患者总次数
  2884. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  2885. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  2886. }
  2887. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  2888. //统计该患者总次数
  2889. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  2890. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  2891. }
  2892. redis := service.RedisClient()
  2893. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2894. redis.Set(key, "", time.Second)
  2895. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2896. //清空key 值
  2897. redis.Set(keyOne, "", time.Second)
  2898. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2899. //清空key 值
  2900. redis.Set(keyTwo, "", time.Second)
  2901. if createErr != nil {
  2902. this.ErrorLog("上机失败:%v", createErr)
  2903. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2904. return
  2905. }
  2906. }
  2907. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2908. var tempdispose string
  2909. // 只针对中能建
  2910. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  2911. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2912. }
  2913. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  2914. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2915. }
  2916. //if blood_drawing > 0 && adminUserInfo.Org.Id == 10629 {
  2917. // tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2918. //}
  2919. var ultrafiltration_rate float64
  2920. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2921. //后期预增脱水量
  2922. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2923. if prescription.ID > 0 {
  2924. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  2925. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2926. 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
  2927. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2928. }
  2929. if adminUserInfo.Org.Id == 10597 { //adminUserInfo.Org.Id == 9538
  2930. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  2931. }
  2932. //针对医师汇
  2933. if adminUserInfo.Org.Id == 10121 {
  2934. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  2935. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  2936. }
  2937. //针对通道
  2938. if adminUserInfo.Org.Id == 10234 {
  2939. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  2940. }
  2941. //针对监利大垸医院
  2942. if template.TemplateId == 41 {
  2943. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  2944. }
  2945. //针对肇庆三鹤血液透析中心
  2946. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  2947. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  2948. }
  2949. if adminUserInfo.Org.Id == 10469 {
  2950. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  2951. }
  2952. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  2953. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  2954. }
  2955. // 只针对方济医院
  2956. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  2957. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  2958. ultrafiltration_rate = value
  2959. }
  2960. //针对
  2961. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  2962. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2963. ultrafiltration_rate = ultrafiltration_rate / 1000
  2964. }
  2965. if adminUserInfo.Org.Id == 10551 {
  2966. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  2967. ultrafiltration_rate = ultrafiltration_rate / 1000
  2968. }
  2969. if adminUserInfo.Org.Id == 10612 || adminUserInfo.Org.Id == 10617 {
  2970. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  2971. ultrafiltration_rate = ultrafiltration_rate / 1000
  2972. }
  2973. if adminUserInfo.Org.Id == 10580 {
  2974. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  2975. ultrafiltration_rate = ultrafiltration_rate / 1000
  2976. }
  2977. if adminUserInfo.Org.Id == 10629 {
  2978. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  2979. ultrafiltration_rate = ultrafiltration_rate / 1000
  2980. }
  2981. if adminUserInfo.Org.Id == 10644 {
  2982. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2983. ultrafiltration_rate = ultrafiltration_rate / 1000
  2984. }
  2985. }
  2986. }
  2987. record := models.MonitoringRecord{
  2988. UserOrgId: adminUserInfo.Org.Id,
  2989. PatientId: patientID,
  2990. DialysisOrderId: dialysisRecord.ID,
  2991. MonitoringDate: schedulestartTime,
  2992. OperateTime: startDate.Unix(),
  2993. // MonitoringTime: recordTime,
  2994. MonitoringNurse: nurseID,
  2995. Dispose: tempdispose,
  2996. UltrafiltrationRate: ultrafiltration_rate,
  2997. UltrafiltrationVolume: 0,
  2998. Status: 1,
  2999. CreatedTime: time.Now().Unix(),
  3000. UpdatedTime: time.Now().Unix(),
  3001. }
  3002. //只针对广慈医院
  3003. 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 {
  3004. // 查询病人是否有透前评估数据
  3005. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3006. //如果有数据就插入
  3007. if errcode == nil {
  3008. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3009. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3010. record.BreathingRate = befor.BreathingRate
  3011. record.PulseFrequency = befor.PulseFrequency
  3012. record.Temperature = befor.Temperature
  3013. }
  3014. }
  3015. // 如果当天有插入数据,则不再往透析纪录里插入数据
  3016. if newdialysisRecord.ID > 0 {
  3017. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  3018. record.Temperature = 36.5
  3019. record.ArterialPressure = -100
  3020. record.DialysateTemperature = 36.5
  3021. record.Conductivity = 14
  3022. record.BreathingRate = "20"
  3023. record.VenousPressure = 80
  3024. record.TransmembranePressure = 60
  3025. record.Dispose = catheter_operation
  3026. }
  3027. //针对新化博翔
  3028. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  3029. record.BloodOxygenSaturation = "99"
  3030. record.Conductivity = 14
  3031. record.DialysateTemperature = 36.5
  3032. record.BreathingRate = "20"
  3033. }
  3034. //针对兰溪人民医院的需求
  3035. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 {
  3036. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3037. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3038. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3039. record.Temperature = befor.Temperature
  3040. record.PulseFrequency = befor.PulseFrequency
  3041. record.BreathingRate = befor.BreathingRate
  3042. }
  3043. //新化博翔
  3044. if adminUserInfo.Org.Id == 10447 {
  3045. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3046. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3047. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3048. record.BreathingRate = befor.BreathingRate
  3049. }
  3050. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3051. record.PulseFrequency = 80
  3052. record.Temperature = 36.5
  3053. }
  3054. //诊断灵山圣康
  3055. if adminUserInfo.Org.Id == 10375 {
  3056. record.Conductivity = 13.8
  3057. record.DialysateTemperature = 37
  3058. record.DialysateFlow = 500
  3059. record.BloodFlowVolume = 200
  3060. record.BreathingRate = "18"
  3061. record.SodiumConcentration = 140
  3062. }
  3063. //江成肾病医院
  3064. if adminUserInfo.Org.Id == 10517 {
  3065. record.SodiumConcentration = 138
  3066. record.DialysateTemperature = 36.5
  3067. }
  3068. err := service.CreateMonitor(&record)
  3069. //记录日志
  3070. byterequest, _ := json.Marshal(record)
  3071. monitorRecordLog := models.XtMonitorRecordLog{
  3072. RecordDate: record.MonitoringDate,
  3073. PatientId: record.PatientId,
  3074. Module: 1,
  3075. AdminUserId: adminUserInfo.AdminUser.Id,
  3076. Ctime: time.Now().Unix(),
  3077. Mtime: 0,
  3078. Status: 1,
  3079. UserOrgId: record.UserOrgId,
  3080. ErrLog: string(byterequest),
  3081. Source: "执行上机时新增监测",
  3082. }
  3083. service.CreateMonitorRecordLog(monitorRecordLog)
  3084. finish := models.XtDialysisFinish{
  3085. IsFinish: 1,
  3086. UserOrgId: adminUserInfo.Org.Id,
  3087. Status: 1,
  3088. Ctime: time.Now().Unix(),
  3089. Mtime: 0,
  3090. Module: 7,
  3091. RecordDate: schedulestartTime,
  3092. Sourse: 1,
  3093. PatientId: patientID,
  3094. }
  3095. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3096. if dialysisFinish.ID == 0 {
  3097. service.CreateDialysisFinish(finish)
  3098. }
  3099. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3100. redis := service.RedisClient()
  3101. //清空key 值
  3102. redis.Set(key, "", time.Second)
  3103. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3104. redis.Set(keyOne, "", time.Second)
  3105. defer redis.Close()
  3106. if err != nil {
  3107. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3108. return
  3109. }
  3110. }
  3111. go func() {
  3112. ssoDomain := beego.AppConfig.String("call_domain")
  3113. api := ssoDomain + "/index/uppatient"
  3114. values := make(url.Values)
  3115. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3116. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3117. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3118. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3119. http.PostForm(api, values)
  3120. }()
  3121. this.ServeSuccessJSON(map[string]interface{}{
  3122. "dialysis_order": newdialysisRecord,
  3123. "monitor": record,
  3124. })
  3125. return
  3126. }
  3127. func (c *DialysisAPIController) PostSolution() {
  3128. id, _ := c.GetInt64("patient", 0)
  3129. recordDateStr := c.GetString("record_date")
  3130. if id <= 0 {
  3131. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3132. return
  3133. }
  3134. adminUserInfo := c.GetMobileAdminUserInfo()
  3135. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3136. if patient.ID == 0 {
  3137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3138. return
  3139. }
  3140. if len(recordDateStr) == 0 {
  3141. recordDateStr = time.Now().Format("2006-01-02")
  3142. }
  3143. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3144. if parseDateErr != nil {
  3145. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3147. return
  3148. }
  3149. mode_id, _ := c.GetInt64("mode_id", 0)
  3150. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3151. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3152. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3153. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3154. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3155. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3156. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3157. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3158. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3159. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3160. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3161. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3162. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3163. kalium, _ := c.GetFloat("kalium", 0)
  3164. sodium, _ := c.GetFloat("sodium", 0)
  3165. calcium, _ := c.GetFloat("calcium", 0)
  3166. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3167. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3168. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3169. glucose, _ := c.GetFloat("glucose", 0)
  3170. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3171. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3172. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3173. conductivity, _ := c.GetFloat("conductivity", 0)
  3174. remark := c.GetString("remark")
  3175. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3176. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3177. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3178. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3179. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3180. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3181. special_medicine_other := c.GetString("special_medicine_other")
  3182. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3183. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3184. blood_access, _ := c.GetInt64("blood_access", 0)
  3185. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3186. body_fluid_other := c.GetString("body_fluid_other")
  3187. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3188. niprocart, _ := c.GetInt64("niprocart", 0)
  3189. jms, _ := c.GetInt64("jms", 0)
  3190. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3191. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3192. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3193. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3194. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3195. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3196. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3197. injector, _ := c.GetInt64("injector", 0)
  3198. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3199. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3200. safe_package, _ := c.GetInt64("package", 0)
  3201. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3202. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3203. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3204. blood := c.GetString("blood")
  3205. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3206. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3207. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3208. displace_speed := c.GetString("displace_speed")
  3209. illness, _ := c.GetInt64("illness")
  3210. amylaceum := c.GetString("amylaceum")
  3211. single_time := c.GetString("single_time")
  3212. single_water := c.GetString("single_water")
  3213. replacement_flow := c.GetString("replacement_flow")
  3214. plasma_separator := c.GetString("plasma_separator")
  3215. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3216. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3217. oxygen_flow := c.GetString("oxygen_flow")
  3218. oxygen_time := c.GetString("oxygen_time")
  3219. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3220. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3221. puncture_needle := c.GetString("puncture_needle")
  3222. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3223. epo := c.GetString("epo")
  3224. epo_count, _ := c.GetFloat("epo_count", 0)
  3225. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3226. pre_impulse := c.GetString("pre_impulse")
  3227. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3228. admin_user_id, _ := c.GetInt64("admin_user_id")
  3229. is_water := c.GetString("is_water")
  3230. add_amount, _ := c.GetFloat("add_amount")
  3231. reduce_amount, _ := c.GetFloat("reduce_amount")
  3232. prescribing_number, _ := c.GetFloat("prescribing_number")
  3233. treatment_remark := c.GetString("treatment_remark")
  3234. prescription_sodium := c.GetString("prescription_sodium")
  3235. start_sodium := c.GetString("start_sodium")
  3236. sodium_curve := c.GetString("sodium_curve")
  3237. var is_war int64
  3238. if is_water == "是" {
  3239. is_war = 1
  3240. }
  3241. if is_water == "否" {
  3242. is_war = 2
  3243. }
  3244. if is_water == "请选择" {
  3245. is_war = 0
  3246. }
  3247. drhy_water := c.GetString("drhy_water")
  3248. dry_water_hour := c.GetString("dry_water_hour")
  3249. water_machine := c.GetString("water_machine")
  3250. dialysis_remark := c.GetString("dialysis_remark")
  3251. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  3252. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  3253. prescription_water, _ := c.GetFloat("prescription_water")
  3254. dialysis_strainer := c.GetString("dialysis_strainer")
  3255. chaptalization := c.GetString("chaptalization")
  3256. washing_time := c.GetString("washing_time")
  3257. warsh_count := c.GetString("warsh_count")
  3258. blood_access_part_id := c.GetString("blood_access_part_id")
  3259. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  3260. dialyzate := c.GetString("dialyzate")
  3261. if mode_id > 0 {
  3262. var str string
  3263. //查找该机构用的是什么透析器
  3264. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  3265. if filedConfig.ID > 0 {
  3266. str = dialyzerPerfusionApparatus
  3267. } else {
  3268. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  3269. }
  3270. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  3271. }
  3272. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3273. //
  3274. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3275. // if appRole.UserType == 3 {
  3276. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3277. // if getPermissionErr != nil {
  3278. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3279. // return
  3280. // } else if headNursePermission == nil {
  3281. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3282. // return
  3283. // }
  3284. // }
  3285. //}
  3286. // 查询信息规挡的设置天数
  3287. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3288. if infor.ID > 0 && infor.WeekDay > 0 {
  3289. var cha_time int64
  3290. timeNowStr := time.Now().Format("2006-01-02")
  3291. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3292. //今日的日期减去设置的日期
  3293. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3294. if cha_time >= recordDate.Unix() {
  3295. //查询审核是否允许
  3296. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  3297. //申请状态不允许的情况 拒绝修改
  3298. if infor.ApplicationStatus != 1 {
  3299. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3300. return
  3301. }
  3302. }
  3303. }
  3304. prescription := models.DialysisPrescription{
  3305. UserOrgId: adminUserInfo.Org.Id,
  3306. PatientId: id,
  3307. RecordDate: recordDate.Unix(),
  3308. ModeId: mode_id,
  3309. DialysisDuration: dialysis_duration,
  3310. Dialyzer: dialyzer,
  3311. PerfusionApparatus: perfusion_apparatus,
  3312. BloodFlowVolume: blood_flow_volume,
  3313. DewaterAmount: dewater_amount,
  3314. DisplaceLiqui: displace_liqui,
  3315. ReplacementWay: replacement_way,
  3316. Anticoagulant: anticoagulant,
  3317. AnticoagulantShouji: anticoagulant_shouji,
  3318. AnticoagulantWeichi: anticoagulant_weichi,
  3319. AnticoagulantZongliang: anticoagulant_zongliang,
  3320. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3321. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3322. Kalium: kalium,
  3323. Sodium: sodium,
  3324. Calcium: calcium,
  3325. Bicarbonate: bicarbonate,
  3326. Glucose: glucose,
  3327. // DryWeight: dry_weight,
  3328. DialysateFlow: dialysate_flow,
  3329. DialysateTemperature: dialysate_temperature,
  3330. Conductivity: conductivity,
  3331. Remark: remark,
  3332. Status: 1,
  3333. CreatedTime: time.Now().Unix(),
  3334. UpdatedTime: time.Now().Unix(),
  3335. DialysisDurationMinute: dialysisDurationMinute,
  3336. DialysisDurationHour: dialysisDurationHour,
  3337. TargetUltrafiltration: targetUltrafiltration,
  3338. DialysateFormulation: dialysateFormulation,
  3339. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3340. BodyFluid: body_fluid,
  3341. SpecialMedicine: special_medicine,
  3342. SpecialMedicineOther: special_medicine_other,
  3343. DisplaceLiquiPart: displace_liqui_part,
  3344. DisplaceLiquiValue: displace_liqui_value,
  3345. BloodAccess: blood_access,
  3346. Ultrafiltration: ultrafiltration,
  3347. BodyFluidOther: body_fluid_other,
  3348. ReplacementTotal: replacement_total,
  3349. Niprocart: niprocart,
  3350. Jms: jms,
  3351. FistulaNeedleSet: fistula_needle_set,
  3352. FistulaNeedleSet16: fistula_needle_set_16,
  3353. Hemoperfusion: hemoperfusion,
  3354. DialyserSterilised: dialyser_sterilised,
  3355. Filtryzer: filtryzer,
  3356. TargetKtv: target_ktv,
  3357. Dialyzers: dialyzers,
  3358. Injector: injector,
  3359. Bloodlines: bloodlines,
  3360. TubingHemodialysis: tubing_hemodialysis,
  3361. Package: safe_package,
  3362. ALiquid: a_liquid,
  3363. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3364. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3365. Blood: blood,
  3366. DialysisDialyszers: dialysis_dialyszers,
  3367. DialysisIrrigation: dialysis_irrigation,
  3368. AntioxidantCommodityName: antioxidant_commodity_name,
  3369. DisplaceSpeed: displace_speed,
  3370. Illness: illness,
  3371. Amylaceum: amylaceum,
  3372. SingleWater: single_water,
  3373. SingleTime: single_time,
  3374. ReplacementFlow: replacement_flow,
  3375. PlasmaSeparator: plasma_separator,
  3376. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  3377. OxygenUptake: oxygen_uptake,
  3378. OxygenTime: oxygen_time,
  3379. OxygenFlow: oxygen_flow,
  3380. HemodialysisPipelines: hemodialysis_pipelines,
  3381. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3382. PunctureNeedle: puncture_needle,
  3383. PunctureNeedleCount: puncture_needle_count,
  3384. Epo: epo,
  3385. EpoCount: epo_count,
  3386. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3387. PreImpulse: impulse,
  3388. AdminUserId: admin_user_id,
  3389. IsWater: is_war,
  3390. DrhyWater: drhy_water,
  3391. DryWaterHour: dry_water_hour,
  3392. WaterMachine: water_machine,
  3393. AddAmount: add_amount,
  3394. ReduceAmount: reduce_amount,
  3395. DialysisRemark: dialysis_remark,
  3396. PrescribingNumber: prescribing_number,
  3397. PrescriptionSodium: prescription_sodium,
  3398. StartSodium: start_sodium,
  3399. SodiumCurve: sodium_curve,
  3400. TreatmentRemark: treatment_remark,
  3401. DialysisFluidFlow: dialysis_fluid_flow,
  3402. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3403. PrescriptionWater: prescription_water,
  3404. DialysisStrainer: dialysis_strainer,
  3405. Chaptalization: chaptalization,
  3406. WashingTime: washing_time,
  3407. WarshCount: warsh_count,
  3408. BloodAccessPartId: blood_access_part_id,
  3409. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3410. Dialyzate: dialyzate,
  3411. }
  3412. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3413. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3414. //
  3415. if appRole.UserType == 2 || appRole.UserType == 1 {
  3416. prescription_doctor = adminUserInfo.AdminUser.Id
  3417. prescription.PrescriptionDoctor = prescription_doctor
  3418. }
  3419. if dialysisPrescription.ID == 0 { //新增
  3420. prescription.Creater = adminUserInfo.AdminUser.Id
  3421. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3422. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3423. }
  3424. } else { //修改
  3425. if dialysisPrescription.Creater == 0 {
  3426. prescription.Creater = adminUserInfo.AdminUser.Id
  3427. } else {
  3428. prescription.Creater = dialysisPrescription.Creater
  3429. if adminUserInfo.Org.Id == 9882 {
  3430. if appRole.UserType == 2 || appRole.UserType == 1 {
  3431. prescription.Creater = adminUserInfo.AdminUser.Id
  3432. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3433. }
  3434. }
  3435. }
  3436. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3437. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3438. }
  3439. //if/**/
  3440. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3441. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  3442. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3443. // if getPermissionErr != nil {
  3444. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3445. // return
  3446. // } else if headNursePermission == nil {
  3447. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3448. // return
  3449. // }
  3450. //}
  3451. //prescription.Creater = dialysisPrescription.Creater
  3452. prescription.CreatedTime = dialysisPrescription.CreatedTime
  3453. prescription.Modifier = adminUserInfo.AdminUser.Id
  3454. prescription.ID = dialysisPrescription.ID
  3455. }
  3456. solution := models.DialysisSolution{
  3457. RegistrarsId: adminUserInfo.AdminUser.Id,
  3458. UserOrgId: adminUserInfo.Org.Id,
  3459. Doctor: prescription_doctor,
  3460. PatientId: id,
  3461. ModeId: mode_id,
  3462. DialysisDuration: dialysis_duration,
  3463. PerfusionApparatus: perfusion_apparatus,
  3464. BloodFlowVolume: blood_flow_volume,
  3465. Dewater: dewater_amount,
  3466. DisplaceLiqui: displace_liqui,
  3467. ReplacementWay: replacement_way,
  3468. Anticoagulant: anticoagulant,
  3469. AnticoagulantShouji: anticoagulant_shouji,
  3470. AnticoagulantWeichi: anticoagulant_weichi,
  3471. AnticoagulantZongliang: anticoagulant_zongliang,
  3472. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3473. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3474. Kalium: kalium,
  3475. Sodium: sodium,
  3476. Calcium: calcium,
  3477. Bicarbonate: bicarbonate,
  3478. Glucose: glucose,
  3479. // DryWeight: dry_weight,
  3480. DialysateFlow: dialysate_flow,
  3481. DialysateTemperature: dialysate_temperature,
  3482. Conductivity: conductivity,
  3483. Remark: remark,
  3484. Status: 1,
  3485. CreatedTime: time.Now().Unix(),
  3486. UpdatedTime: time.Now().Unix(),
  3487. DialysisDurationMinute: dialysisDurationMinute,
  3488. DialysisDurationHour: dialysisDurationHour,
  3489. TargetUltrafiltration: targetUltrafiltration,
  3490. DialysateFormulation: dialysateFormulation,
  3491. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3492. BodyFluid: body_fluid,
  3493. SpecialMedicine: special_medicine,
  3494. SpecialMedicineOther: special_medicine_other,
  3495. DisplaceLiquiPart: displace_liqui_part,
  3496. DisplaceLiquiValue: displace_liqui_value,
  3497. BloodAccess: blood_access,
  3498. Ultrafiltration: ultrafiltration,
  3499. BodyFluidOther: body_fluid_other,
  3500. ReplacementTotal: replacement_total,
  3501. TargetKtv: target_ktv,
  3502. DialysisDialyszers: dialysis_dialyszers,
  3503. DialysisIrrigation: dialysis_irrigation,
  3504. HemodialysisPipelines: hemodialysis_pipelines,
  3505. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3506. PunctureNeedle: puncture_needle,
  3507. PunctureNeedleCount: puncture_needle_count,
  3508. Epo: epo,
  3509. EpoCount: epo_count,
  3510. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3511. PreImpulse: impulse,
  3512. SolutionStatus: 1,
  3513. DialysisRemark: dialysis_remark,
  3514. PrescribingNumber: prescribing_number,
  3515. PrescriptionSodium: prescription_sodium,
  3516. StartSodium: start_sodium,
  3517. SodiumCurve: sodium_curve,
  3518. TreatmentRemark: treatment_remark,
  3519. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3520. DialysisFluidFlow: dialysis_fluid_flow,
  3521. PrescriptionWater: prescription_water,
  3522. DialysisStrainer: dialysis_strainer,
  3523. Chaptalization: chaptalization,
  3524. WashingTime: washing_time,
  3525. WarshCount: warsh_count,
  3526. BloodAccessPartId: blood_access_part_id,
  3527. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3528. Dialyzate: dialyzate,
  3529. }
  3530. //针对河间咸的
  3531. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  3532. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  3533. solution.DisplaceLiquiPart = 0
  3534. solution.DisplaceLiquiValue = 0
  3535. }
  3536. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  3537. prescription.DisplaceLiquiPart = 0
  3538. prescription.DisplaceLiquiValue = 0
  3539. }
  3540. }
  3541. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  3542. if solution.PrescribingNumber == 0 {
  3543. solution.PrescribingNumber = 1
  3544. }
  3545. if prescription.PrescribingNumber == 0 {
  3546. prescription.PrescribingNumber = 1
  3547. }
  3548. if solution.PrescribingNumber == 0 && id == 14682 {
  3549. solution.PrescribingNumber = 2
  3550. }
  3551. if solution.PrescribingNumber == 0 && id == 18560 {
  3552. solution.PrescribingNumber = 2
  3553. }
  3554. if prescription.PrescribingNumber == 0 && id == 14682 {
  3555. prescription.PrescribingNumber = 2
  3556. }
  3557. if prescription.PrescribingNumber == 0 && id == 18560 {
  3558. prescription.PrescribingNumber = 2
  3559. }
  3560. }
  3561. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  3562. //记录日志
  3563. byterequest, _ := json.Marshal(prescription)
  3564. prescriptionLog := models.XtDialysisPrescriptionLog{
  3565. UserOrgId: prescription.UserOrgId,
  3566. Ctime: time.Now().Unix(),
  3567. Mtime: 0,
  3568. ErrLog: string(byterequest),
  3569. AdminUserId: adminUserInfo.AdminUser.Id,
  3570. RecordDate: prescription.RecordDate,
  3571. PatientId: prescription.PatientId,
  3572. Source: "手机端新增长期处方",
  3573. Status: 1,
  3574. }
  3575. service.CreatePrescriptionLog(prescriptionLog)
  3576. finish := models.XtDialysisFinish{
  3577. IsFinish: 1,
  3578. UserOrgId: adminUserInfo.Org.Id,
  3579. Status: 1,
  3580. Ctime: time.Now().Unix(),
  3581. Mtime: 0,
  3582. Module: 1,
  3583. RecordDate: recordDate.Unix(),
  3584. Sourse: 1,
  3585. PatientId: id,
  3586. }
  3587. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  3588. if dialysisFinish.ID == 0 {
  3589. service.CreateDialysisFinish(finish)
  3590. }
  3591. //获取最新1条
  3592. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  3593. //更新状态
  3594. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  3595. //长沙南雅医院,自动生成抗凝剂的临时处方
  3596. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  3597. if prescribing_number == 0 {
  3598. prescribing_number = 1
  3599. }
  3600. advice := models.DoctorAdvice{
  3601. UserOrgId: adminUserInfo.Org.Id,
  3602. PatientId: id,
  3603. GroupNo: 0,
  3604. AdviceType: 2,
  3605. RecordDate: recordDate.Unix(),
  3606. AdviceDate: recordDate.Unix(),
  3607. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  3608. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  3609. AdviceDesc: "",
  3610. ReminderDate: 0,
  3611. SingleDose: prescription.AnticoagulantZongliang,
  3612. SingleDoseUnit: "iu",
  3613. DrugSpec: 0,
  3614. DrugSpecUnit: "",
  3615. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  3616. PrescribingNumberUnit: "支",
  3617. DeliveryWay: "静脉注射",
  3618. ExecutionFrequency: "上机前",
  3619. AdviceDoctor: 0,
  3620. Status: 1,
  3621. CreatedTime: time.Now().Unix(),
  3622. UpdatedTime: time.Now().Unix(),
  3623. IsPrescription: 1,
  3624. ExecutionState: 2,
  3625. StopState: 2,
  3626. IsSettle: 2,
  3627. }
  3628. // 查询排班信息
  3629. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3630. if schedulePatient.ID > 0 {
  3631. if schedulePatient.ScheduleType == 1 {
  3632. advice.StartTime = recordDate.Unix() + 6.5*60*60
  3633. }
  3634. if schedulePatient.ScheduleType == 2 {
  3635. advice.StartTime = recordDate.Unix() + 9*60*60
  3636. }
  3637. }
  3638. // 抗凝剂名称
  3639. switch anticoagulant {
  3640. case 1:
  3641. advice.AdviceName = "无肝素"
  3642. break
  3643. case 2:
  3644. advice.AdviceName = "普通肝素"
  3645. break
  3646. case 3:
  3647. advice.AdviceName = "低分子肝素"
  3648. break
  3649. case 4:
  3650. advice.AdviceName = "阿加曲班"
  3651. break
  3652. case 5:
  3653. advice.AdviceName = "枸橼酸钠"
  3654. break
  3655. case 6:
  3656. advice.AdviceName = "低分子肝素钙"
  3657. break
  3658. case 7:
  3659. advice.AdviceName = "低分子肝素钠"
  3660. break
  3661. case 8:
  3662. advice.AdviceName = "依诺肝素"
  3663. break
  3664. case 9:
  3665. advice.AdviceName = "达肝素"
  3666. break
  3667. case 10:
  3668. advice.AdviceName = "体外抗凝"
  3669. break
  3670. case 11:
  3671. advice.AdviceName = "那曲肝素"
  3672. break
  3673. case 12:
  3674. advice.AdviceName = "无抗凝剂"
  3675. break
  3676. }
  3677. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  3678. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  3679. advice.AdviceDoctor = appRole.AdminUserId
  3680. }
  3681. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  3682. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  3683. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  3684. advice.AdviceName = "低分子肝素钠注射液"
  3685. // 修改患者临时医嘱里的抗凝剂医嘱
  3686. advice.ID = advicePrescription.ID
  3687. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  3688. } else {
  3689. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  3690. advice.AdviceName = "低分子肝素钠注射液"
  3691. service.CreateDoctorAdvice(&advice)
  3692. }
  3693. }
  3694. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  3695. redis := service.RedisClient()
  3696. defer redis.Close()
  3697. //清空key 值
  3698. redis.Set(key, "", time.Second)
  3699. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  3700. redis.Set(keyOne, "", time.Second)
  3701. }
  3702. //获取key,清空redis
  3703. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3704. redis := service.RedisClient()
  3705. defer redis.Close()
  3706. //清空key 值
  3707. redis.Set(key, "", time.Second)
  3708. //清空长期医嘱的key
  3709. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3710. redis.Set(soulution_key, "", time.Second)
  3711. //查询最近透析准备表里是否存在 透析器 灌流器
  3712. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3713. redis.Set(keyOne, "", time.Second)
  3714. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  3715. redis.Set(keyTwo, "", time.Second)
  3716. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  3717. redis.Set(keyThree, "", time.Second)
  3718. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  3719. redis.Set(keyFour, "", time.Second)
  3720. //splitStr := strings.Split(dialysis_dialyszers, ",")
  3721. //
  3722. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  3723. //
  3724. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  3725. //if len(mation)>0{
  3726. // for _, item := range splitStr {
  3727. // for _,it := range mation{
  3728. // if(item == it.SpecificationName){
  3729. //
  3730. // //查询最近一次的透析器
  3731. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3732. //
  3733. // if errcode == gorm.ErrRecordNotFound{
  3734. // //插入数据
  3735. // prepare := models.DialysisBeforePrepare{
  3736. // UserOrgId: adminUserInfo.Org.Id,
  3737. // PatientId: id,
  3738. // RecordDate: recordDate.Unix(),
  3739. // GoodTypeId: it.GoodTypeId,
  3740. // GoodId: it.ID,
  3741. // Count: 1,
  3742. // Ctime: time.Now().Unix(),
  3743. // Creater: adminUserInfo.AdminUser.Id,
  3744. // Status:1,
  3745. //
  3746. // }
  3747. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3748. // fmt.Println("",errcode)
  3749. // }
  3750. // }
  3751. // }
  3752. //
  3753. // }
  3754. //
  3755. // for _, item := range splitIrrigation {
  3756. // for _,it := range mation{
  3757. // if(item == it.SpecificationName){
  3758. // //查询最近一次的透析器
  3759. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3760. // if errcode == gorm.ErrRecordNotFound{
  3761. // //插入数据
  3762. // prepare := models.DialysisBeforePrepare{
  3763. // UserOrgId: adminUserInfo.Org.Id,
  3764. // PatientId: id,
  3765. // RecordDate: recordDate.Unix(),
  3766. // GoodTypeId: it.GoodTypeId,
  3767. // GoodId: it.ID,
  3768. // Count: 1,
  3769. // Ctime: time.Now().Unix(),
  3770. // Creater: adminUserInfo.AdminUser.Id,
  3771. // Status:1,
  3772. //
  3773. // }
  3774. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3775. // fmt.Println(errcode)
  3776. // }
  3777. // }
  3778. // }
  3779. // }
  3780. //}
  3781. c.ServeSuccessJSON(map[string]interface{}{
  3782. "solution": &solution,
  3783. "prescription": &prescription,
  3784. })
  3785. }
  3786. func (c *DialysisAPIController) GetAcceptsAssessment() {
  3787. patient, _ := c.GetInt64("patient", 0)
  3788. adminUserInfo := c.GetMobileAdminUserInfo()
  3789. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  3790. c.ServeSuccessJSON(map[string]interface{}{
  3791. "receiveTreatmentAsses": receiveTreatmentAsses,
  3792. })
  3793. }
  3794. func (this *DialysisAPIController) PostSignInfo() {
  3795. patientID, _ := this.GetInt64("patient_id")
  3796. recordDateStr := this.GetString("date")
  3797. if patientID <= 0 {
  3798. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3799. return
  3800. }
  3801. if len(recordDateStr) == 0 {
  3802. recordDateStr = time.Now().Format("2006-01-02")
  3803. }
  3804. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3805. if parseDateErr != nil {
  3806. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3807. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3808. return
  3809. }
  3810. adminInfo := this.GetMobileAdminUserInfo()
  3811. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  3812. if err != nil {
  3813. this.ErrorLog("签名失败:%v", err)
  3814. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3815. return
  3816. }
  3817. this.ServeSuccessJSON(map[string]interface{}{
  3818. "doctor_id": adminInfo.AdminUser.Id,
  3819. })
  3820. }
  3821. func (this *DialysisAPIController) GetLastMonitorRecord() {
  3822. patientID, _ := this.GetInt64("patient_id")
  3823. adminInfo := this.GetMobileAdminUserInfo()
  3824. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  3825. this.ServeSuccessJSON(map[string]interface{}{
  3826. "monitor": record,
  3827. })
  3828. }
  3829. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  3830. thisTime := time.Now()
  3831. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  3832. timeLayout := "2006-01-02 15:04:05"
  3833. loc, _ := time.LoadLocation("Local")
  3834. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3835. theAssessmentDateTime := theStartTime.Unix()
  3836. patientID, _ := this.GetInt64("patient_id")
  3837. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  3838. adminInfo := this.GetMobileAdminUserInfo()
  3839. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  3840. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  3841. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  3842. var ultrafiltration_rate float64
  3843. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  3844. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  3845. fmt.Println(evaluation)
  3846. fmt.Println("prescription.ID", prescription.ID)
  3847. if prescription.ID > 0 {
  3848. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3849. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3850. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  3851. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3852. record.UltrafiltrationRate = ultrafiltration_rate
  3853. }
  3854. if adminInfo.Org.Id == 10597 {
  3855. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3856. record.UltrafiltrationRate = ultrafiltration_rate
  3857. }
  3858. if adminInfo.Org.Id == 10510 {
  3859. record.UltrafiltrationRate = 0
  3860. }
  3861. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  3862. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  3863. record.UltrafiltrationRate = ultrafiltration_rate
  3864. }
  3865. if template.TemplateId == 20 || template.TemplateId == 22 {
  3866. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3867. record.UltrafiltrationRate = ultrafiltration_rate
  3868. }
  3869. // 只针对方济医院
  3870. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  3871. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3872. ultrafiltration_rate = value
  3873. record.UltrafiltrationRate = ultrafiltration_rate
  3874. }
  3875. if template.TemplateId == 41 || template.TemplateId == 47 {
  3876. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3877. record.UltrafiltrationRate = ultrafiltration_rate
  3878. }
  3879. if template.TemplateId == 43 {
  3880. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3881. record.UltrafiltrationRate = ultrafiltration_rate
  3882. }
  3883. if template.TemplateId == 46 || template.TemplateId == 54 {
  3884. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3885. record.UltrafiltrationRate = ultrafiltration_rate
  3886. }
  3887. if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 9829 || adminInfo.Org.Id == 10440 || adminInfo.Org.Id == 10610 {
  3888. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  3889. record.UltrafiltrationRate = ultrafiltration_rate
  3890. }
  3891. if adminInfo.Org.Id == 10469 {
  3892. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  3893. record.UltrafiltrationRate = ultrafiltration_rate
  3894. }
  3895. if adminInfo.Org.Id == 10471 {
  3896. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3897. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  3898. }
  3899. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 {
  3900. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3901. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  3902. }
  3903. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 || adminInfo.Org.Id == 10629 {
  3904. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3905. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  3906. }
  3907. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 {
  3908. record.UltrafiltrationRate = 0
  3909. }
  3910. //if template.TemplateId == 47 {
  3911. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3912. // record.UltrafiltrationRate = ultrafiltration_rate
  3913. //}
  3914. }
  3915. }
  3916. // record.UltrafiltrationRate = ultrafiltration_rate
  3917. record.UltrafiltrationVolume = 0
  3918. 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
  3919. if ultrafiltration_rate > 0 {
  3920. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  3921. record.UltrafiltrationVolume = value
  3922. }
  3923. }
  3924. 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
  3925. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  3926. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3927. record.UltrafiltrationVolume = ultrafiltration_volume
  3928. }
  3929. }
  3930. if adminInfo.Org.Id == 10597 {
  3931. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3932. record.UltrafiltrationVolume = ultrafiltration_volume
  3933. }
  3934. //长沙南雅
  3935. 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 || adminInfo.Org.Id == 10610 {
  3936. if ultrafiltration_rate > 0 {
  3937. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3938. record.UltrafiltrationVolume = ultrafiltration_volume
  3939. }
  3940. }
  3941. if adminInfo.Org.Id == 10471 {
  3942. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3943. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  3944. }
  3945. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 {
  3946. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3947. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  3948. }
  3949. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  3950. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3951. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  3952. }
  3953. //长沙南雅累计血容量自动计算
  3954. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  3955. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  3956. //}
  3957. if template.TemplateId == 47 || template.TemplateId == 54 {
  3958. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  3959. }
  3960. if adminInfo.Org.Id == 10510 {
  3961. record.UltrafiltrationVolume = 0
  3962. }
  3963. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  3964. this.ServeSuccessJSON(map[string]interface{}{
  3965. "monitor": record,
  3966. "lastMonitorRecordList": lastMonitorRecordList,
  3967. })
  3968. }
  3969. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  3970. record_id, _ := this.GetInt64("id")
  3971. nurseID, _ := this.GetInt64("start_nurse")
  3972. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  3973. bedID, _ := this.GetInt64("bed")
  3974. start_time := this.GetString("start_time")
  3975. schedual_type, _ := this.GetInt64("schedual_type")
  3976. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  3977. change_nurse, _ := this.GetInt64("change_nurse")
  3978. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  3979. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  3980. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  3981. patient_id, _ := this.GetInt64("patient_id")
  3982. record_date, _ := this.GetInt64("record_date")
  3983. puncture_needle := this.GetString("puncture_needle")
  3984. puncture_way := this.GetString("puncture_way")
  3985. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  3986. dialysis_irrigation := this.GetString("dialysis_irrigation")
  3987. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  3988. nuclein_date_str := this.GetString("nuclein_date_str")
  3989. order_remark := this.GetString("order_remark")
  3990. schedule_remark := this.GetString("schedule_remark")
  3991. catheter_operation := this.GetString("catheter_operation")
  3992. blood_flow_volume := this.GetString("blood_flow_volume")
  3993. blood_drawing, _ := this.GetInt64("blood_drawing")
  3994. if record_id == 0 {
  3995. this.ErrorLog("id:%v", record_id)
  3996. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3997. return
  3998. }
  3999. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  4000. if parseStartDateErr != nil {
  4001. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  4002. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4003. return
  4004. }
  4005. adminUserInfo := this.GetMobileAdminUserInfo()
  4006. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4007. if getNurseErr != nil {
  4008. this.ErrorLog("获取护士失败:%v", getNurseErr)
  4009. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4010. return
  4011. } else if nurse == nil {
  4012. this.ErrorLog("护士不存在")
  4013. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4014. return
  4015. }
  4016. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  4017. //if getNurseErr != nil {
  4018. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  4019. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4020. // return
  4021. //} else if nurse == nil {
  4022. // this.ErrorLog("护士不存在")
  4023. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4024. // return
  4025. //}
  4026. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  4027. if getDeviceNumberErr != nil {
  4028. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  4029. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4030. return
  4031. } else if deviceNumber == nil {
  4032. this.ErrorLog("床位号不存在")
  4033. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4034. return
  4035. }
  4036. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  4037. //
  4038. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  4039. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4040. // if getPermissionErr != nil {
  4041. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4042. // return
  4043. // } else if headNursePermission == nil {
  4044. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4045. // return
  4046. // }
  4047. //}
  4048. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  4049. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  4050. timeLayout := "2006-01-02 15:04:05"
  4051. loc, _ := time.LoadLocation("Local")
  4052. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4053. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  4054. schedulestartTime := theStartTime.Unix()
  4055. scheduleendTime := theEndTime.Unix()
  4056. var theNucleinDate int64
  4057. timeLayoutOne := "2006-01-02"
  4058. if len(nuclein_date_str) > 0 {
  4059. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  4060. if err != nil {
  4061. utils.ErrorLog(err.Error())
  4062. }
  4063. theNucleinDate = theTime.Unix()
  4064. }
  4065. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  4066. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  4067. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4068. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  4069. if err == gorm.ErrRecordNotFound { //空床位
  4070. // 修改了床位逻辑
  4071. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4072. if daySchedule.ID > 0 {
  4073. //daySchedule.BedId = bedID
  4074. //daySchedule.PartitionId = deviceNumber.ZoneID
  4075. //daySchedule.ScheduleType = schedual_type
  4076. //daySchedule.UpdatedTime = time.Now().Unix()
  4077. //err := service.UpdateSchedule(&daySchedule)
  4078. xtSchedule := models.Schedule{
  4079. PartitionId: deviceNumber.ZoneID,
  4080. BedId: bedID,
  4081. ScheduleType: schedual_type,
  4082. UpdatedTime: time.Now().Unix(),
  4083. }
  4084. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4085. if err != nil {
  4086. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4087. return
  4088. }
  4089. }
  4090. } else if err == nil {
  4091. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  4092. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4093. if daySchedule.ID > 0 {
  4094. //daySchedule.BedId = bedID
  4095. //daySchedule.PartitionId = deviceNumber.ZoneID
  4096. //
  4097. //daySchedule.ScheduleType = schedual_type
  4098. //daySchedule.UpdatedTime = time.Now().Unix()
  4099. //err := service.UpdateSchedule(&daySchedule)
  4100. xtSchedule := models.Schedule{
  4101. PartitionId: deviceNumber.ZoneID,
  4102. BedId: bedID,
  4103. ScheduleType: schedual_type,
  4104. UpdatedTime: time.Now().Unix(),
  4105. }
  4106. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4107. if err != nil {
  4108. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4109. return
  4110. }
  4111. }
  4112. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  4113. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  4114. return
  4115. }
  4116. } else if err != nil {
  4117. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4118. return
  4119. }
  4120. }
  4121. dialysisRecord := &models.DialysisOrder{
  4122. ID: record_id,
  4123. UserOrgId: adminUserInfo.Org.Id,
  4124. BedID: bedID,
  4125. StartNurse: nurseID,
  4126. StartTime: startDate.Unix(),
  4127. PunctureNurse: puncture_nurse,
  4128. Creator: adminUserInfo.AdminUser.Id,
  4129. Modifier: adminUserInfo.AdminUser.Id,
  4130. WashpipeNurse: washpipe_nurse,
  4131. SchedualType: schedual_type,
  4132. ChangeNurse: change_nurse,
  4133. DifficultPunctureNurse: difficult_puncture_nurse,
  4134. NewFistulaNurse: new_fistula_nurse,
  4135. QualityNurseId: quality_nurse_id,
  4136. PunctureNeedle: puncture_needle,
  4137. PunctureWay: puncture_way,
  4138. DialysisDialyszers: dialysis_dialyszers,
  4139. DialysisIrrigation: dialysis_irrigation,
  4140. BloodAccessId: blood_access_id,
  4141. NucleinDate: theNucleinDate,
  4142. OrderRemark: order_remark,
  4143. ScheduleRemark: schedule_remark,
  4144. CatheterOperation: catheter_operation,
  4145. BloodFlowVolume: blood_flow_volume,
  4146. BloodDrawing: blood_drawing,
  4147. }
  4148. //修改床位号需要重新消毒
  4149. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  4150. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4151. //查询第一条监测
  4152. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4153. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  4154. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  4155. redis := service.RedisClient()
  4156. //清空key 值
  4157. redis.Set(key, "", time.Second)
  4158. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  4159. redis.Set(keyOne, "", time.Second)
  4160. defer redis.Close()
  4161. }
  4162. // 查询信息规挡的设置天数
  4163. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4164. if infor.ID > 0 && infor.WeekDay > 0 {
  4165. var cha_time int64
  4166. timeNowStr := time.Now().Format("2006-01-02")
  4167. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4168. //今日的日期减去设置的日期
  4169. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4170. if cha_time >= record_date {
  4171. //查询审核是否允许
  4172. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  4173. //申请状态不允许的情况 拒绝修改
  4174. if infor.ApplicationStatus != 1 {
  4175. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4176. return
  4177. }
  4178. }
  4179. }
  4180. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  4181. order, _ := service.GetLastPatientOrder(record_id)
  4182. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  4183. redis := service.RedisClient()
  4184. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  4185. redis.Set(key, "", time.Second)
  4186. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4187. //清空key 值
  4188. redis.Set(keyOne, "", time.Second)
  4189. scheduleDateStartOne := startDate.Format("2006-01-02")
  4190. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4191. redis.Set(keyTwo, "", time.Second)
  4192. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  4193. redis.Set(keyThree, "", time.Second)
  4194. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4195. redis.Set(keyFour, "", time.Second)
  4196. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  4197. redis.Set(keyFive, "", time.Second)
  4198. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  4199. redis.Set(keySix, "", time.Second)
  4200. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  4201. redis.Set(keySeven, "", time.Second)
  4202. if updateErr != nil {
  4203. this.ErrorLog("修改上机失败:%v", updateErr)
  4204. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4205. return
  4206. }
  4207. if updateErr == nil {
  4208. if tempDialysisRecord.Stage == 2 {
  4209. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  4210. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4211. fmt.Println(value)
  4212. a, b := math.Modf(value)
  4213. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4214. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4215. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4216. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  4217. redis := service.RedisClient()
  4218. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  4219. redis.Set(key, "", time.Second)
  4220. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  4221. redis.Set(keyOne, "", time.Second)
  4222. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4223. //清空key 值
  4224. redis.Set(keySix, "", time.Second)
  4225. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4226. redis.Set(keySeven, "", time.Second)
  4227. redis.Close()
  4228. if updateAssessmentErr != nil {
  4229. utils.ErrorLog("%v", updateAssessmentErr)
  4230. }
  4231. }
  4232. }
  4233. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4234. this.ServeSuccessJSON(map[string]interface{}{
  4235. "dialysis_order": dialysisRecords,
  4236. })
  4237. }
  4238. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  4239. record_id, _ := c.GetInt64("id")
  4240. nurseID, _ := c.GetInt64("nurse")
  4241. end_time := c.GetString("end_time")
  4242. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  4243. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  4244. catheter := c.GetString("catheter")
  4245. cruor := c.GetString("cruor")
  4246. mission := c.GetString("mission")
  4247. condenser := c.GetString("condenser")
  4248. if record_id <= 0 || nurseID <= 0 {
  4249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4250. return
  4251. }
  4252. adminUserInfo := c.GetMobileAdminUserInfo()
  4253. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4254. if getNurseErr != nil {
  4255. c.ErrorLog("获取护士失败:%v", getNurseErr)
  4256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4257. return
  4258. } else if nurse == nil {
  4259. c.ErrorLog("护士不存在")
  4260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4261. return
  4262. }
  4263. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  4264. if parseEndDateErr != nil {
  4265. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  4266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4267. return
  4268. }
  4269. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  4270. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  4271. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4272. // if getPermissionErr != nil {
  4273. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4274. // return
  4275. // } else if headNursePermission == nil {
  4276. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4277. // return
  4278. // }
  4279. //}
  4280. // 查询信息规挡的设置天数
  4281. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4282. if infor.ID > 0 {
  4283. var cha_time int64
  4284. timeNowStr := time.Now().Format("2006-01-02")
  4285. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4286. //今日的日期减去设置的日期
  4287. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4288. if cha_time >= tempDialysisRecords.DialysisDate {
  4289. //查询审核是否允许
  4290. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  4291. //申请状态不允许的情况 拒绝修改
  4292. if infor.ApplicationStatus != 1 {
  4293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4294. return
  4295. }
  4296. }
  4297. }
  4298. dialysisRecord := &models.DialysisOrder{
  4299. ID: record_id,
  4300. UserOrgId: adminUserInfo.Org.Id,
  4301. EndTime: endDate.Unix(),
  4302. FinishNurse: nurseID,
  4303. FinishModifier: adminUserInfo.AdminUser.Id,
  4304. PuncturePointHaematoma: puncture_point_haematoma,
  4305. BloodAccessInternalFistula: blood_access_internal_fistula,
  4306. Catheter: catheter,
  4307. Cruor: cruor,
  4308. Mission: mission,
  4309. Condenser: condenser,
  4310. }
  4311. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  4312. redis := service.RedisClient()
  4313. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  4314. //清空key 值
  4315. redis.Set(key, "", time.Second)
  4316. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4317. //清空key 值
  4318. redis.Set(keyOne, "", time.Second)
  4319. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4320. redis.Set(keySeven, "", time.Second)
  4321. redis.Close()
  4322. if updateErr != nil {
  4323. c.ErrorLog("修改下机失败:%v", updateErr)
  4324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4325. return
  4326. }
  4327. if updateErr == nil {
  4328. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  4329. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4330. a, b := math.Modf(value)
  4331. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4332. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4333. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4334. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  4335. redis := service.RedisClient()
  4336. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  4337. redis.Set(keyTen, "", time.Second)
  4338. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  4339. redis.Set(keyTwo, "", time.Second)
  4340. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  4341. redis.Set(key, "", time.Second)
  4342. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4343. redis.Set(keyThree, "", time.Second)
  4344. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4345. redis.Set(keySeven, "", time.Second)
  4346. defer redis.Close()
  4347. if updateAssessmentErr != nil {
  4348. utils.ErrorLog("%v", updateAssessmentErr)
  4349. }
  4350. }
  4351. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4352. c.ServeSuccessJSON(map[string]interface{}{
  4353. "dialysis_order": dialysisRecords,
  4354. })
  4355. }
  4356. func (c *DialysisAPIController) GetLongAdvice() {
  4357. patient_id, _ := c.GetInt64("id")
  4358. adminUserInfo := c.GetMobileAdminUserInfo()
  4359. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4360. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4361. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4362. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4363. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4364. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4365. c.ServeSuccessJSON(map[string]interface{}{
  4366. "status": "1",
  4367. })
  4368. return
  4369. } else { //开启推送提醒
  4370. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4371. var advice_three []*models.DoctorAdvice
  4372. recordDateStr := time.Now().Format("2006-01-02")
  4373. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4374. nowtime := recordDate.Unix()
  4375. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  4376. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  4377. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  4378. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  4379. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  4380. for _, advice := range advices {
  4381. if advice.FrequencyType == 3 {
  4382. t := time.Now()
  4383. week := int(t.Weekday())
  4384. fmt.Println(t.Weekday())
  4385. fmt.Println(week)
  4386. switch week {
  4387. case 1:
  4388. if strings.Index(advice.WeekDay, "周一") == -1 {
  4389. advice_three = append(advice_three, advice)
  4390. }
  4391. break
  4392. case 2:
  4393. if strings.Index(advice.WeekDay, "周二") == -1 {
  4394. advice_three = append(advice_three, advice)
  4395. }
  4396. break
  4397. case 3:
  4398. if strings.Index(advice.WeekDay, "周三") == -1 {
  4399. advice_three = append(advice_three, advice)
  4400. }
  4401. break
  4402. case 4:
  4403. if strings.Index(advice.WeekDay, "周四") == -1 {
  4404. advice_three = append(advice_three, advice)
  4405. }
  4406. break
  4407. case 5:
  4408. if strings.Index(advice.WeekDay, "周五") == -1 {
  4409. advice_three = append(advice_three, advice)
  4410. }
  4411. break
  4412. case 6:
  4413. if strings.Index(advice.WeekDay, "周六") == -1 {
  4414. advice_three = append(advice_three, advice)
  4415. }
  4416. break
  4417. case 0:
  4418. if strings.Index(advice.WeekDay, "周日") == -1 {
  4419. advice_three = append(advice_three, advice)
  4420. }
  4421. break
  4422. }
  4423. }
  4424. }
  4425. for _, advice := range advices_two {
  4426. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4427. now := p.Unix()
  4428. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4429. dayStr2 := "-" + dayStr
  4430. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4431. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4432. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4433. for _, ad := range advices {
  4434. advice_three = append(advice_three, ad)
  4435. }
  4436. }
  4437. if err == nil {
  4438. c.ServeSuccessJSON(map[string]interface{}{
  4439. "status": "2",
  4440. "advices": advices,
  4441. "advices_two": RemoveRepeatedElement(advice_three),
  4442. "is_open_remind": config.IsOpenRemind,
  4443. "his_config_open": hisConfig.IsOpen,
  4444. "is_advice_open": is_advice_open.IsAdviceOpen,
  4445. "prescription_open": prescription_open.IsOpen,
  4446. })
  4447. }
  4448. }
  4449. }
  4450. func (c *DialysisAPIController) GetLongAdviceOne() {
  4451. patient_id, _ := c.GetInt64("id")
  4452. startTime := c.GetString("schedule_date")
  4453. timeLayout := "2006-01-02"
  4454. loc, _ := time.LoadLocation("Local")
  4455. var theStartTime int64
  4456. if len(startTime) > 0 {
  4457. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4458. if err != nil {
  4459. utils.ErrorLog(err.Error())
  4460. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4461. return
  4462. }
  4463. theStartTime = theTime.Unix()
  4464. }
  4465. adminUserInfo := c.GetMobileAdminUserInfo()
  4466. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4467. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4468. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4469. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4470. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4471. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4472. c.ServeSuccessJSON(map[string]interface{}{
  4473. "status": "1",
  4474. })
  4475. return
  4476. } else { //开启推送提醒
  4477. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4478. var advice_three []*models.DoctorAdvice
  4479. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  4480. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  4481. for _, advice := range advices {
  4482. if advice.FrequencyType == 3 {
  4483. t := time.Now()
  4484. week := int(t.Weekday())
  4485. fmt.Println(t.Weekday())
  4486. fmt.Println(week)
  4487. switch week {
  4488. case 1:
  4489. if strings.Index(advice.WeekDay, "周一") == -1 {
  4490. advice_three = append(advice_three, advice)
  4491. }
  4492. break
  4493. case 2:
  4494. if strings.Index(advice.WeekDay, "周二") == -1 {
  4495. advice_three = append(advice_three, advice)
  4496. }
  4497. break
  4498. case 3:
  4499. if strings.Index(advice.WeekDay, "周三") == -1 {
  4500. advice_three = append(advice_three, advice)
  4501. }
  4502. break
  4503. case 4:
  4504. if strings.Index(advice.WeekDay, "周四") == -1 {
  4505. advice_three = append(advice_three, advice)
  4506. }
  4507. break
  4508. case 5:
  4509. if strings.Index(advice.WeekDay, "周五") == -1 {
  4510. advice_three = append(advice_three, advice)
  4511. }
  4512. break
  4513. case 6:
  4514. if strings.Index(advice.WeekDay, "周六") == -1 {
  4515. advice_three = append(advice_three, advice)
  4516. }
  4517. break
  4518. case 0:
  4519. if strings.Index(advice.WeekDay, "周日") == -1 {
  4520. advice_three = append(advice_three, advice)
  4521. }
  4522. break
  4523. }
  4524. }
  4525. }
  4526. for _, advice := range advices_two {
  4527. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4528. now := p.Unix()
  4529. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4530. dayStr2 := "-" + dayStr
  4531. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4532. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4533. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4534. for _, ad := range advices {
  4535. advice_three = append(advice_three, ad)
  4536. }
  4537. }
  4538. if err == nil {
  4539. c.ServeSuccessJSON(map[string]interface{}{
  4540. "status": "2",
  4541. "advices": advices,
  4542. "advices_two": RemoveRepeatedElement(advice_three),
  4543. "is_open_remind": config.IsOpenRemind,
  4544. "his_config_open": hisConfig.IsOpen,
  4545. "is_advice_open": is_advice_open.IsAdviceOpen,
  4546. "prescription_open": prescription_open.IsOpen,
  4547. })
  4548. }
  4549. }
  4550. }
  4551. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  4552. newArr = make([]*models.DoctorAdvice, 0)
  4553. for i := 0; i < len(arr); i++ {
  4554. repeat := false
  4555. for j := i + 1; j < len(arr); j++ {
  4556. if arr[i].ID == arr[j].ID {
  4557. repeat = true
  4558. break
  4559. }
  4560. }
  4561. if !repeat {
  4562. newArr = append(newArr, arr[i])
  4563. }
  4564. }
  4565. return
  4566. }
  4567. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  4568. patient, _ := c.GetInt64("id", 0)
  4569. groupNo, _ := c.GetInt64("groupno", 0)
  4570. if patient <= 0 {
  4571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4572. return
  4573. }
  4574. adminUserInfo := c.GetMobileAdminUserInfo()
  4575. dataBody := make(map[string]interface{}, 0)
  4576. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4577. if err != nil {
  4578. utils.ErrorLog(err.Error())
  4579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4580. return
  4581. }
  4582. utils.ErrorLog("%v", dataBody)
  4583. timeLayout := "2006-01-02 15:04"
  4584. loc, _ := time.LoadLocation("Local")
  4585. timeLayout2 := "2006-01-02"
  4586. loc2, _ := time.LoadLocation("Local")
  4587. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4588. utils.ErrorLog("advice_type")
  4589. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4590. return
  4591. }
  4592. adviceType := int64(2)
  4593. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4594. utils.ErrorLog("advice_date")
  4595. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4596. return
  4597. }
  4598. adviceDate, _ := dataBody["advice_date"].(string)
  4599. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  4600. AdviceDate := theTime.Unix()
  4601. RecordDate := theTime.Unix()
  4602. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4603. utils.ErrorLog("start_time")
  4604. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4605. return
  4606. }
  4607. startTime, _ := dataBody["start_time"].(string)
  4608. if len(startTime) == 0 {
  4609. utils.ErrorLog("len(start_time) == 0")
  4610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4611. return
  4612. }
  4613. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  4614. if err != nil {
  4615. utils.ErrorLog(err.Error())
  4616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4617. return
  4618. }
  4619. StartTime := theTime.Unix()
  4620. Remark := ""
  4621. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4622. remark, _ := dataBody["remark"].(string)
  4623. Remark = remark
  4624. }
  4625. var advices []*models.GroupAdvice
  4626. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  4627. utils.ErrorLog("advices")
  4628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4629. return
  4630. }
  4631. adviceNames := dataBody["advices"].([]interface{})
  4632. for _, adviceNameMap := range adviceNames {
  4633. adviceNameM := adviceNameMap.(map[string]interface{})
  4634. var advice models.GroupAdvice
  4635. advice.Remark = Remark
  4636. advice.AdviceType = adviceType
  4637. advice.StartTime = StartTime
  4638. advice.AdviceDate = AdviceDate
  4639. advice.RecordDate = RecordDate
  4640. advice.Status = 1
  4641. advice.CreatedTime = time.Now().Unix()
  4642. advice.UpdatedTime = time.Now().Unix()
  4643. advice.StopState = 2
  4644. advice.ExecutionState = 2
  4645. advice.UserOrgId = adminUserInfo.Org.Id
  4646. advice.PatientId = patient
  4647. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4648. advice.IsSettle = 2
  4649. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  4650. utils.ErrorLog("advice_name")
  4651. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4652. return
  4653. }
  4654. adviceName, _ := adviceNameM["advice_name"].(string)
  4655. if len(adviceName) == 0 {
  4656. utils.ErrorLog("len(advice_name) == 0")
  4657. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4658. return
  4659. }
  4660. advice.AdviceName = adviceName
  4661. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  4662. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  4663. advice.DrugSpec = drugSpec
  4664. }
  4665. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  4666. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  4667. advice.AdviceDesc = adviceDesc
  4668. }
  4669. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  4670. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  4671. advice.DrugSpecUnit = drugSpecUnit
  4672. }
  4673. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  4674. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  4675. // advice.SingleDose = singleDose
  4676. //}
  4677. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  4678. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4679. advice.SingleDose = adviceNameM["single_dose"].(float64)
  4680. }
  4681. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  4682. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  4683. advice.SingleDoseUnit = singleDoseUnit
  4684. }
  4685. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  4686. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  4687. // advice.PrescribingNumber = prescribingNumber
  4688. //}
  4689. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  4690. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4691. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  4692. }
  4693. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  4694. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  4695. advice.PrescribingNumberUnit = prescribingNumberUnit
  4696. }
  4697. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  4698. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  4699. advice.DeliveryWay = deliveryWay
  4700. }
  4701. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  4702. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4703. advice.ExecutionFrequency = executionFrequency
  4704. }
  4705. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  4706. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  4707. advice.FrequencyType = frequency_type
  4708. }
  4709. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  4710. day_count := int64(adviceNameM["day_count"].(float64))
  4711. advice.DayCount = day_count
  4712. }
  4713. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  4714. week_day, _ := adviceNameM["week_day"].(string)
  4715. advice.WeekDay = week_day
  4716. }
  4717. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  4718. way := int64(adviceNameM["way"].(float64))
  4719. advice.Way = way
  4720. }
  4721. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  4722. drug_id := int64(adviceNameM["drug_id"].(float64))
  4723. advice.DrugId = drug_id
  4724. }
  4725. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  4726. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  4727. advice.DrugNameId = drug_name_id
  4728. }
  4729. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  4730. remark, _ := adviceNameM["remark"].(string)
  4731. advice.Remark = remark
  4732. }
  4733. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  4734. groupno := int64(adviceNameM["groupno"].(float64))
  4735. advice.GroupNo = groupno
  4736. }
  4737. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  4738. template_id, _ := adviceNameM["template_id"].(string)
  4739. advice.TemplateId = template_id
  4740. }
  4741. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  4742. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4743. advice.ExecutionFrequency = executionFrequency
  4744. }
  4745. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  4746. children := adviceNameM["child"].([]interface{})
  4747. if len(children) > 0 {
  4748. for _, childrenMap := range children {
  4749. childMap := childrenMap.(map[string]interface{})
  4750. var child models.GroupAdvice
  4751. child.Remark = Remark
  4752. child.AdviceType = adviceType
  4753. child.StartTime = StartTime
  4754. child.AdviceDate = AdviceDate
  4755. child.RecordDate = RecordDate
  4756. child.Status = 1
  4757. child.CreatedTime = time.Now().Unix()
  4758. child.UpdatedTime = time.Now().Unix()
  4759. child.StopState = 2
  4760. child.ExecutionState = 2
  4761. child.UserOrgId = adminUserInfo.Org.Id
  4762. child.PatientId = patient
  4763. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  4764. child.IsSettle = 1
  4765. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  4766. utils.ErrorLog("child advice_name")
  4767. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4768. return
  4769. }
  4770. childAdviceName, _ := childMap["advice_name"].(string)
  4771. if len(childAdviceName) == 0 {
  4772. utils.ErrorLog("len(child advice_name) == 0")
  4773. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4774. return
  4775. }
  4776. child.AdviceName = childAdviceName
  4777. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  4778. childAdviceDesc, _ := childMap["advice_desc"].(string)
  4779. child.AdviceDesc = childAdviceDesc
  4780. }
  4781. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  4782. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  4783. child.DrugSpec = childDrugSpec
  4784. }
  4785. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  4786. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  4787. child.DrugSpecUnit = childDrugSpecUnit
  4788. }
  4789. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  4790. child.SingleDose = childMap["single_dose"].(float64)
  4791. }
  4792. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  4793. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  4794. child.SingleDoseUnit = childSingleDoseUnit
  4795. }
  4796. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  4797. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  4798. }
  4799. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  4800. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  4801. child.PrescribingNumberUnit = childPrescribingNumberUnit
  4802. }
  4803. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  4804. groupno := int64(childMap["groupno"].(float64))
  4805. advice.GroupNo = groupno
  4806. }
  4807. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  4808. remark, _ := childMap["remark"].(string)
  4809. child.Remark = remark
  4810. }
  4811. child.DeliveryWay = advice.DeliveryWay
  4812. child.ExecutionFrequency = advice.ExecutionFrequency
  4813. advice.Children = append(advice.Children, &child)
  4814. }
  4815. }
  4816. }
  4817. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  4818. if temp_advice.ID == 0 {
  4819. advices = append(advices, &advice)
  4820. }
  4821. }
  4822. if len(advices) > 0 {
  4823. finish := models.XtDialysisFinish{
  4824. IsFinish: 1,
  4825. UserOrgId: adminUserInfo.Org.Id,
  4826. Status: 1,
  4827. Ctime: time.Now().Unix(),
  4828. Mtime: 0,
  4829. Module: 4,
  4830. RecordDate: AdviceDate,
  4831. Sourse: 1,
  4832. PatientId: patient,
  4833. }
  4834. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  4835. if dialysisFinish.ID == 0 {
  4836. service.CreateDialysisFinish(finish)
  4837. }
  4838. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 9671 {
  4839. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  4840. for _, item := range advices {
  4841. byterequest, _ := json.Marshal(item)
  4842. adviceLog := models.XtDoctorAdviceLog{
  4843. UserOrgId: adminUserInfo.Org.Id,
  4844. PatientId: patient,
  4845. AdminUserId: adminUserInfo.AdminUser.Id,
  4846. Module: 1,
  4847. ErrLog: string(byterequest),
  4848. Status: 1,
  4849. Ctime: time.Now().Unix(),
  4850. Mtime: 0,
  4851. Source: "手机端医嘱推送",
  4852. RecordDate: item.AdviceDate,
  4853. }
  4854. service.CreateDoctorAdviceLog(adviceLog)
  4855. }
  4856. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  4857. redis := service.RedisClient()
  4858. //清空key 值
  4859. redis.Set(key, "", time.Second)
  4860. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  4861. redis.Set(keyOne, "", time.Second)
  4862. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4863. defer redis.Close()
  4864. redis.Set(keyThree, "", time.Second)
  4865. if err != nil {
  4866. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4867. return
  4868. }
  4869. c.ServeSuccessJSON(map[string]interface{}{
  4870. "msg": "ok",
  4871. "advices": list,
  4872. })
  4873. } else {
  4874. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  4875. for _, item := range advices {
  4876. byterequest, _ := json.Marshal(item)
  4877. adviceLog := models.XtDoctorAdviceLog{
  4878. UserOrgId: adminUserInfo.Org.Id,
  4879. PatientId: patient,
  4880. AdminUserId: adminUserInfo.AdminUser.Id,
  4881. Module: 1,
  4882. ErrLog: string(byterequest),
  4883. Status: 1,
  4884. Ctime: time.Now().Unix(),
  4885. Mtime: 0,
  4886. Source: "手机端医嘱推送",
  4887. RecordDate: item.AdviceDate,
  4888. }
  4889. service.CreateDoctorAdviceLog(adviceLog)
  4890. }
  4891. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  4892. redis := service.RedisClient()
  4893. //清空key 值
  4894. redis.Set(key, "", time.Second)
  4895. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  4896. redis.Set(keyOne, "", time.Second)
  4897. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4898. defer redis.Close()
  4899. redis.Set(keyThree, "", time.Second)
  4900. if err != nil {
  4901. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4902. return
  4903. }
  4904. c.ServeSuccessJSON(map[string]interface{}{
  4905. "msg": "ok",
  4906. "advices": list,
  4907. })
  4908. }
  4909. } else {
  4910. c.ServeSuccessJSON(map[string]interface{}{
  4911. "msg": "ok",
  4912. })
  4913. }
  4914. return
  4915. }
  4916. func (c *DialysisAPIController) UploadDryWeight() {
  4917. patient_id, _ := c.GetInt64("id")
  4918. dry_weight, _ := c.GetFloat("dry_weight")
  4919. doctor_id, _ := c.GetInt64("doctor_id")
  4920. remark := c.GetString("remark")
  4921. adminUserInfo := c.GetMobileAdminUserInfo()
  4922. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  4923. if err == gorm.ErrRecordNotFound {
  4924. dryWeight := &models.SgjPatientDryweight{
  4925. PatientId: patient_id,
  4926. DryWeight: dry_weight,
  4927. Remakes: remark,
  4928. Ctime: time.Now().Unix(),
  4929. Mtime: time.Now().Unix(),
  4930. Creator: doctor_id,
  4931. Status: 1,
  4932. UserOrgId: adminUserInfo.Org.Id,
  4933. AdjustedValue: "/",
  4934. UserId: adminUserInfo.AdminUser.Id,
  4935. }
  4936. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4937. redis := service.RedisClient()
  4938. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  4939. redis.Set(keyOne, "", time.Second)
  4940. loc, _ := time.LoadLocation("Local")
  4941. nowTime := time.Now()
  4942. nowDay := nowTime.Format("2006-01-02")
  4943. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4944. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4945. redis.Set(key, "", time.Second)
  4946. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4947. redis.Set(keyTwo, "", time.Second)
  4948. redis.Close()
  4949. if createErr == nil {
  4950. c.ServeSuccessJSON(map[string]interface{}{
  4951. "msg": "提交成功",
  4952. "weight": dryWeight,
  4953. })
  4954. }
  4955. } else {
  4956. dryWeight := &models.SgjPatientDryweight{
  4957. PatientId: patient_id,
  4958. DryWeight: dry_weight,
  4959. Remakes: remark,
  4960. Ctime: time.Now().Unix(),
  4961. Mtime: time.Now().Unix(),
  4962. Creator: doctor_id,
  4963. Status: 1,
  4964. UserOrgId: adminUserInfo.Org.Id,
  4965. AdjustedValue: "/",
  4966. UserId: adminUserInfo.AdminUser.Id,
  4967. }
  4968. var value float64
  4969. value = dry_weight - weightAdjust.DryWeight
  4970. if value < 0 {
  4971. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  4972. } else if value == 0 {
  4973. dryWeight.AdjustedValue = "/"
  4974. } else if value > 0 {
  4975. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  4976. }
  4977. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4978. redis := service.RedisClient()
  4979. loc, _ := time.LoadLocation("Local")
  4980. nowTime := time.Now()
  4981. nowDay := nowTime.Format("2006-01-02")
  4982. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4983. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  4984. redis.Set(keyOne, "", time.Second)
  4985. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4986. redis.Set(key, "", time.Second)
  4987. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4988. redis.Set(keyTwo, "", time.Second)
  4989. redis.Close()
  4990. if createErr == nil {
  4991. c.ServeSuccessJSON(map[string]interface{}{
  4992. "msg": "提交成功",
  4993. "weight": dryWeight,
  4994. })
  4995. }
  4996. }
  4997. }
  4998. func (c *DialysisAPIController) GetSolution() {
  4999. patient_id, _ := c.GetInt64("patient_id")
  5000. mode_id, _ := c.GetInt64("mode_id")
  5001. adminUserInfo := c.GetMobileAdminUserInfo()
  5002. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5003. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5004. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  5005. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  5006. if err != nil {
  5007. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5008. return
  5009. }
  5010. c.ServeSuccessJSON(map[string]interface{}{
  5011. "solution": solution,
  5012. "prescription": prescription,
  5013. "system_prescription": system_prescription,
  5014. "dialysisPrescription": dialysisPrescription,
  5015. })
  5016. }
  5017. func (c *DialysisAPIController) GetSchedule() {
  5018. schedual_type, _ := c.GetInt64("schedual_type")
  5019. adminUserInfo := c.GetMobileAdminUserInfo()
  5020. scheduleTime, _ := c.GetInt64("record_date")
  5021. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  5022. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  5023. c.ServeSuccessJSON(map[string]interface{}{
  5024. "number": deviceNumber,
  5025. "list": list,
  5026. })
  5027. }
  5028. func (c *DialysisAPIController) GetPatientId() {
  5029. id, _ := c.GetInt64("id")
  5030. //orgid := c.GetMobileAdminUserInfo().Org.Id
  5031. patientId, _ := service.GetPatientId(id)
  5032. //获取该患者的所有传染病
  5033. list, _ := service.GetPatientInfectious(id)
  5034. c.ServeSuccessJSON(map[string]interface{}{
  5035. "patient": patientId,
  5036. "infectioulist": list,
  5037. })
  5038. }
  5039. func (this *DialysisAPIController) GetDialysisSchedule() {
  5040. schedualDate := this.GetString("date")
  5041. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5042. if parseDateErr != nil {
  5043. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5044. return
  5045. }
  5046. adminInfo := this.GetMobileAdminUserInfo()
  5047. orgID := adminInfo.Org.Id
  5048. redis := service.RedisClient()
  5049. defer redis.Close()
  5050. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  5051. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  5052. if len(scheduals) > 0 {
  5053. //缓存数据
  5054. scheduals_json, err := json.Marshal(scheduals)
  5055. if err == nil {
  5056. redis.Set(key, scheduals_json, time.Second*30)
  5057. }
  5058. }
  5059. this.ServeSuccessJSON(map[string]interface{}{
  5060. "scheduals": scheduals,
  5061. })
  5062. }
  5063. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  5064. change_type, _ := this.GetInt64("type", 0)
  5065. record_date := this.GetString("record_time")
  5066. patient_id, _ := this.GetInt64("patient_id", 0)
  5067. timeLayout := "2006-01-02"
  5068. loc, _ := time.LoadLocation("Local")
  5069. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5070. record_time := theAdviceRecordTime.Unix()
  5071. adminUserInfo := this.GetMobileAdminUserInfo()
  5072. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  5073. if err == nil {
  5074. if len(advices) == 0 {
  5075. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5076. return
  5077. } else {
  5078. this.ServeSuccessJSON(map[string]interface{}{
  5079. "advices": advices,
  5080. "schedule": sch,
  5081. })
  5082. return
  5083. }
  5084. } else {
  5085. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5086. return
  5087. }
  5088. }
  5089. func (c *DialysisAPIController) CreateConsumables() {
  5090. record_date := c.GetString("record_time")
  5091. patient_id, _ := c.GetInt64("patient_id", 0)
  5092. active, _ := c.GetInt64("active")
  5093. adminUser := c.GetMobileAdminUserInfo()
  5094. timeLayout := "2006-01-02"
  5095. loc, _ := time.LoadLocation("Local")
  5096. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5097. record_time := theRecordTime.Unix()
  5098. // 查询信息规挡的设置天数
  5099. orgid := c.GetMobileAdminUserInfo().Org.Id
  5100. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  5101. if infor.ID > 0 {
  5102. var cha_time int64
  5103. timeNowStr := time.Now().Format("2006-01-02")
  5104. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5105. //今日的日期减去设置的日期
  5106. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5107. if cha_time >= record_time {
  5108. //查询审核是否允许
  5109. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  5110. //申请状态不允许的情况 拒绝修改
  5111. if infor.ApplicationStatus != 1 {
  5112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5113. return
  5114. }
  5115. }
  5116. }
  5117. dataBody := make(map[string]interface{}, 0)
  5118. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5119. if err != nil {
  5120. utils.ErrorLog(err.Error())
  5121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5122. return
  5123. }
  5124. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5125. var beforePrepares []*models.DialysisBeforePrepareGoods
  5126. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5127. var dialysisBefor []*models.DialysisBeforePrepare
  5128. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5129. goods, _ := dataBody["goods"].([]interface{})
  5130. if len(goods) > 0 {
  5131. for _, item := range goods {
  5132. items := item.(map[string]interface{})
  5133. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5134. utils.ErrorLog("good_id")
  5135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5136. return
  5137. }
  5138. good_id := int64(items["good_id"].(float64))
  5139. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5140. utils.ErrorLog("good_type_id")
  5141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5142. return
  5143. }
  5144. good_type_id := int64(items["good_type_id"].(float64))
  5145. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5146. utils.ErrorLog("count")
  5147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5148. return
  5149. }
  5150. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5151. commdity_code := items["commdity_code"].(string)
  5152. fmt.Println("commdity", commdity_code)
  5153. prepareGoods := &models.DialysisBeforePrepareGoods{
  5154. GoodTypeId: good_type_id,
  5155. GoodId: good_id,
  5156. Count: count,
  5157. StorehouseId: houseConfig.StorehouseOutInfo,
  5158. }
  5159. beforePrepares = append(beforePrepares, prepareGoods)
  5160. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  5161. GoodTypeId: good_type_id,
  5162. GoodId: good_id,
  5163. Count: count,
  5164. StorehouseId: houseConfig.StorehouseOutInfo,
  5165. }
  5166. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  5167. prepare := &models.DialysisBeforePrepare{
  5168. GoodTypeId: good_type_id,
  5169. GoodId: good_id,
  5170. Count: count,
  5171. PatientId: patient_id,
  5172. RecordDate: record_time,
  5173. UserOrgId: adminUser.Org.Id,
  5174. Status: 1,
  5175. Ctime: time.Now().Unix(),
  5176. Creater: adminUser.AdminUser.Id,
  5177. CommdityCode: commdity_code,
  5178. StorehouseId: houseConfig.StorehouseOutInfo,
  5179. }
  5180. dialysisBefor = append(dialysisBefor, prepare)
  5181. }
  5182. }
  5183. //查询是否有库存
  5184. for _, item := range dialysisBefor {
  5185. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5186. if err == gorm.ErrRecordNotFound {
  5187. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5188. c.ServeSuccessJSON(map[string]interface{}{
  5189. "message": "1",
  5190. "good_name": goodObj.GoodName,
  5191. "specification_name": goodObj.SpecificationName,
  5192. })
  5193. return
  5194. }
  5195. if err != nil {
  5196. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5197. c.ServeSuccessJSON(map[string]interface{}{
  5198. "message": "1",
  5199. "good_name": goodObj.GoodName,
  5200. "specification_name": goodObj.SpecificationName,
  5201. })
  5202. return
  5203. }
  5204. }
  5205. //新增
  5206. if active == 1 && len(goods) > 0 {
  5207. for _, item := range dialysisBefor {
  5208. dialyPrepareOne := models.DialysisBeforePrepare{
  5209. GoodTypeId: item.GoodTypeId,
  5210. GoodId: item.GoodId,
  5211. PatientId: item.PatientId,
  5212. RecordDate: item.RecordDate,
  5213. UserOrgId: item.UserOrgId,
  5214. Count: item.Count,
  5215. Ctime: time.Now().Unix(),
  5216. Creater: item.Creater,
  5217. CommdityCode: item.CommdityCode,
  5218. Status: 1,
  5219. StorehouseId: houseConfig.StorehouseOutInfo,
  5220. }
  5221. //先清除再插入
  5222. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5223. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  5224. //查询默认仓库
  5225. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5226. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5227. var total_count int64
  5228. for _, it := range stockList {
  5229. total_count += it.StockCount
  5230. }
  5231. //基础库插入数据
  5232. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5233. //更新库存
  5234. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5235. var flush_count int64
  5236. for _, it := range goodList {
  5237. flush_count += it.StockCount
  5238. }
  5239. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5240. }
  5241. if err == nil {
  5242. c.ServeSuccessJSON(map[string]interface{}{
  5243. "msg": "保存成功",
  5244. "message": "2",
  5245. })
  5246. return
  5247. } else {
  5248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5249. return
  5250. }
  5251. }
  5252. if len(beforePrepares) > 0 && active == 2 {
  5253. for _, item := range beforePrepares {
  5254. //1.查看该患者该耗材型号最后一次出库数量
  5255. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  5256. //判断当前出库数量和最后一次出库数量的大小
  5257. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  5258. if item.Count <= goodInfo.Count {
  5259. //退库
  5260. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  5261. //查询今日出库数据
  5262. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5263. for _, it := range list {
  5264. prepare := models.DialysisBeforePrepare{
  5265. UserOrgId: it.OrgId,
  5266. PatientId: patient_id,
  5267. RecordDate: it.RecordTime,
  5268. GoodId: it.GoodId,
  5269. GoodTypeId: it.GoodTypeId,
  5270. Count: it.Count,
  5271. Ctime: time.Now().Unix(),
  5272. Creater: adminUser.AdminUser.Id,
  5273. Status: 1,
  5274. StorehouseId: houseConfig.StorehouseOutInfo,
  5275. }
  5276. //删除准备表数据
  5277. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5278. service.CreateDialysisBeforePrepareOne(&prepare)
  5279. }
  5280. }
  5281. var last_total int64
  5282. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  5283. if item.Count >= goodInfo.Count {
  5284. //查询当前批次当前耗材最后一条出库数据
  5285. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5286. //计算当前出库和最后一次出库数据相差数据
  5287. last_total = item.Count - lastOutInfo.Count
  5288. //查询该批次剩余库存
  5289. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  5290. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  5291. if lastInfo.StockCount >= last_total {
  5292. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5293. //查询今日出库数据
  5294. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5295. for _, it := range list {
  5296. prepare := models.DialysisBeforePrepare{
  5297. UserOrgId: it.OrgId,
  5298. PatientId: patient_id,
  5299. RecordDate: it.RecordTime,
  5300. GoodId: it.GoodId,
  5301. GoodTypeId: it.GoodTypeId,
  5302. Count: it.Count,
  5303. Ctime: time.Now().Unix(),
  5304. Creater: adminUser.AdminUser.Id,
  5305. Status: 1,
  5306. StorehouseId: houseConfig.StorehouseOutInfo,
  5307. }
  5308. //删除准备表数据
  5309. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5310. service.CreateDialysisBeforePrepareOne(&prepare)
  5311. //查询默认仓库
  5312. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5313. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5314. var total_count int64
  5315. for _, it := range stockList {
  5316. total_count += it.StockCount
  5317. }
  5318. //基础库插入数据
  5319. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5320. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5321. var flush_count int64
  5322. for _, it := range goodList {
  5323. flush_count += it.StockCount
  5324. }
  5325. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5326. }
  5327. }
  5328. //如果库存不够,则出库到下一个批次
  5329. if lastInfo.StockCount < last_total {
  5330. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5331. //查询今日出库数据
  5332. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5333. for _, it := range list {
  5334. prepare := models.DialysisBeforePrepare{
  5335. UserOrgId: it.OrgId,
  5336. PatientId: patient_id,
  5337. RecordDate: it.RecordTime,
  5338. GoodId: it.GoodId,
  5339. GoodTypeId: it.GoodTypeId,
  5340. Count: it.Count,
  5341. Ctime: time.Now().Unix(),
  5342. Creater: adminUser.AdminUser.Id,
  5343. Status: 1,
  5344. StorehouseId: houseConfig.StorehouseOutInfo,
  5345. }
  5346. //删除准备表数据
  5347. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5348. service.CreateDialysisBeforePrepareOne(&prepare)
  5349. //查询默认仓库
  5350. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5351. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5352. var total_count int64
  5353. for _, it := range stockList {
  5354. total_count += it.StockCount
  5355. }
  5356. //基础库插入数据
  5357. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5358. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5359. var flush_count int64
  5360. for _, it := range goodList {
  5361. flush_count += it.StockCount
  5362. }
  5363. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5364. }
  5365. if err != nil {
  5366. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5367. c.ServeSuccessJSON(map[string]interface{}{
  5368. "message": "1",
  5369. "good_name": goodObj.GoodName,
  5370. "specification_name": goodObj.SpecificationName,
  5371. })
  5372. return
  5373. }
  5374. }
  5375. }
  5376. if err != nil {
  5377. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5378. c.ServeSuccessJSON(map[string]interface{}{
  5379. "message": "1",
  5380. "good_name": goodObj.GoodName,
  5381. "specification_name": goodObj.SpecificationName,
  5382. })
  5383. return
  5384. }
  5385. }
  5386. }
  5387. }
  5388. var errs error
  5389. if errs == nil {
  5390. c.ServeSuccessJSON(map[string]interface{}{
  5391. "msg": "提交成功",
  5392. "message": "2",
  5393. "good_name": "",
  5394. "specification_name": "",
  5395. })
  5396. return
  5397. } else {
  5398. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5399. return
  5400. }
  5401. }
  5402. func (c *DialysisAPIController) CreateStockOutInfo() {
  5403. patient_id, _ := c.GetInt64("patient_id", 0)
  5404. record_date := c.GetString("record_time")
  5405. if patient_id <= 0 {
  5406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5407. return
  5408. }
  5409. adminInfo := c.GetMobileAdminUserInfo()
  5410. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  5411. timeLayout := "2006-01-02"
  5412. loc, _ := time.LoadLocation("Local")
  5413. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5414. record_time := theRecordTime.Unix()
  5415. // 查询信息规挡的设置天数
  5416. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  5417. if infor.ID > 0 && infor.WeekDay > 0 {
  5418. var cha_time int64
  5419. timeNowStr := time.Now().Format("2006-01-02")
  5420. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5421. //今日的日期减去设置的日期
  5422. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5423. if cha_time >= record_time {
  5424. //查询审核是否允许
  5425. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  5426. //申请状态不允许的情况 拒绝修改
  5427. if infor.ApplicationStatus != 1 {
  5428. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5429. return
  5430. }
  5431. }
  5432. }
  5433. //创建步骤表
  5434. finish := models.XtDialysisFinish{
  5435. IsFinish: 1,
  5436. UserOrgId: adminInfo.Org.Id,
  5437. Status: 1,
  5438. Ctime: time.Now().Unix(),
  5439. Mtime: 0,
  5440. Module: 11,
  5441. RecordDate: record_time,
  5442. Sourse: 1,
  5443. PatientId: patient_id,
  5444. }
  5445. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  5446. if dialysisFinish.ID == 0 {
  5447. service.CreateDialysisFinish(finish)
  5448. }
  5449. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  5450. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  5451. //去重
  5452. consumables = RemoveRepeatedGood(consumables)
  5453. if adminInfo.Org.Id == 9919 {
  5454. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5455. //查询是否有库存
  5456. for _, item := range consumables {
  5457. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5458. if item.Count > warehouse.Count {
  5459. goodErrcode := models.XtGoodErrcode{
  5460. UserOrgId: item.UserOrgId,
  5461. Errcode: "自动出库库存不足",
  5462. GoodId: item.GoodId,
  5463. Status: 1,
  5464. Ctime: time.Now().Unix(),
  5465. Mtime: 0,
  5466. Count: 0,
  5467. StockCount: 0,
  5468. Creater: creator,
  5469. BatchNumberId: warehouse.ID,
  5470. WarehouseOutId: 0,
  5471. }
  5472. service.CreateGoodErrcode(goodErrcode)
  5473. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5474. c.ServeSuccessJSON(map[string]interface{}{
  5475. "message": "1",
  5476. "good_name": goodObj.GoodName,
  5477. "specification_name": goodObj.SpecificationName,
  5478. })
  5479. return
  5480. }
  5481. }
  5482. //查询是否有出库单
  5483. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5484. if err == gorm.ErrRecordNotFound {
  5485. //没有记录,则创建出库单
  5486. timeStr := time.Now().Format("2006-01-02")
  5487. timeArr := strings.Split(timeStr, "-")
  5488. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5489. total = total + 1
  5490. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5491. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5492. number = number + total
  5493. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5494. creater := adminInfo.AdminUser.Id
  5495. warehouseOut := models.WarehouseOut{
  5496. WarehouseOutOrderNumber: warehousing_out_order,
  5497. OperationTime: time.Now().Unix(),
  5498. OrgId: adminInfo.Org.Id,
  5499. Creater: creater,
  5500. Ctime: time.Now().Unix(),
  5501. Status: 1,
  5502. WarehouseOutTime: record_time,
  5503. Dealer: 0,
  5504. Manufacturer: 0,
  5505. Type: 1,
  5506. IsSys: 1,
  5507. StorehouseId: houseConfig.StorehouseOutInfo,
  5508. IsCheck: 1,
  5509. }
  5510. err := service.AddSigleWarehouseOut(&warehouseOut)
  5511. if err != nil {
  5512. goodErrcode := models.XtGoodErrcode{
  5513. UserOrgId: adminInfo.Org.Id,
  5514. Errcode: "创建出库单失败",
  5515. GoodId: 0,
  5516. Status: 1,
  5517. Ctime: time.Now().Unix(),
  5518. Mtime: 0,
  5519. Count: 0,
  5520. StockCount: 0,
  5521. Creater: creator,
  5522. BatchNumberId: 0,
  5523. WarehouseOutId: 0,
  5524. }
  5525. service.CreateGoodErrcode(goodErrcode)
  5526. utils.TraceLog("创建出库单失败 err = %v", err)
  5527. } else {
  5528. for _, item := range consumables {
  5529. //出库
  5530. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  5531. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  5532. if err == nil {
  5533. goodErrcode := models.XtGoodErrcode{
  5534. UserOrgId: adminInfo.Org.Id,
  5535. Errcode: "自动出库接口报错",
  5536. GoodId: 0,
  5537. Status: 1,
  5538. Ctime: time.Now().Unix(),
  5539. Mtime: 0,
  5540. Count: 0,
  5541. StockCount: 0,
  5542. Creater: creator,
  5543. BatchNumberId: 0,
  5544. WarehouseOutId: 0,
  5545. }
  5546. service.CreateGoodErrcode(goodErrcode)
  5547. utils.TraceLog("创建出库单失败 err = %v", err)
  5548. }
  5549. //查询
  5550. //出库数量相加
  5551. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5552. if errs != nil {
  5553. goodErrcode := models.XtGoodErrcode{
  5554. UserOrgId: item.UserOrgId,
  5555. Errcode: "创建剩余库存字段报错",
  5556. GoodId: item.GoodId,
  5557. Status: 1,
  5558. Ctime: time.Now().Unix(),
  5559. Mtime: 0,
  5560. Count: 0,
  5561. StockCount: 0,
  5562. Creater: creater,
  5563. BatchNumberId: 0,
  5564. WarehouseOutId: 0,
  5565. }
  5566. service.CreateGoodErrcode(goodErrcode)
  5567. }
  5568. }
  5569. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5570. if len(list) == 0 {
  5571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5572. return
  5573. }
  5574. for _, item := range list {
  5575. prepare := models.DialysisBeforePrepare{
  5576. UserOrgId: adminInfo.Org.Id,
  5577. PatientId: patient_id,
  5578. RecordDate: record_time,
  5579. GoodId: item.GoodId,
  5580. GoodTypeId: item.GoodTypeId,
  5581. Count: item.Count,
  5582. Creater: adminInfo.AdminUser.Id,
  5583. Status: 1,
  5584. Ctime: time.Now().Unix(),
  5585. StorehouseId: houseConfig.StorehouseOutInfo,
  5586. }
  5587. //清空准备表数据
  5588. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5589. if err != nil {
  5590. goodErrcode := models.XtGoodErrcode{
  5591. UserOrgId: item.OrgId,
  5592. Errcode: "自动出库清空准备表数据报错",
  5593. GoodId: item.GoodId,
  5594. Status: 1,
  5595. Ctime: time.Now().Unix(),
  5596. Mtime: 0,
  5597. Count: 0,
  5598. StockCount: 0,
  5599. Creater: creater,
  5600. BatchNumberId: 0,
  5601. WarehouseOutId: 0,
  5602. }
  5603. service.CreateGoodErrcode(goodErrcode)
  5604. }
  5605. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  5606. if errs != nil {
  5607. goodErrcode := models.XtGoodErrcode{
  5608. UserOrgId: item.OrgId,
  5609. Errcode: "自动出库创建准备表数据报错",
  5610. GoodId: item.GoodId,
  5611. Status: 1,
  5612. Ctime: time.Now().Unix(),
  5613. Mtime: 0,
  5614. Count: 0,
  5615. StockCount: 0,
  5616. Creater: creater,
  5617. BatchNumberId: 0,
  5618. WarehouseOutId: 0,
  5619. }
  5620. service.CreateGoodErrcode(goodErrcode)
  5621. }
  5622. //查询默认仓库
  5623. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5624. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5625. var total_count int64
  5626. for _, it := range stockList {
  5627. total_count += it.StockCount
  5628. }
  5629. //基础库插入数据
  5630. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5631. if errcodes != nil {
  5632. goodErrcode := models.XtGoodErrcode{
  5633. UserOrgId: item.OrgId,
  5634. Errcode: "自动出库基础库插入数据",
  5635. GoodId: item.GoodId,
  5636. Status: 1,
  5637. Ctime: time.Now().Unix(),
  5638. Mtime: 0,
  5639. Count: 0,
  5640. StockCount: 0,
  5641. Creater: creater,
  5642. BatchNumberId: 0,
  5643. WarehouseOutId: 0,
  5644. }
  5645. service.CreateGoodErrcode(goodErrcode)
  5646. }
  5647. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5648. var flush_count int64
  5649. for _, it := range goodList {
  5650. flush_count += it.StockCount
  5651. }
  5652. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5653. if errsss != nil {
  5654. goodErrcode := models.XtGoodErrcode{
  5655. UserOrgId: item.OrgId,
  5656. Errcode: "自动出库剩余库存更新数据",
  5657. GoodId: item.GoodId,
  5658. Status: 1,
  5659. Ctime: time.Now().Unix(),
  5660. Mtime: 0,
  5661. Count: 0,
  5662. StockCount: 0,
  5663. Creater: creater,
  5664. BatchNumberId: 0,
  5665. WarehouseOutId: 0,
  5666. }
  5667. service.CreateGoodErrcode(goodErrcode)
  5668. }
  5669. }
  5670. }
  5671. //
  5672. } else if err == nil {
  5673. for _, item := range consumables {
  5674. //出库
  5675. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  5676. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  5677. if err != nil {
  5678. goodErrcode := models.XtGoodErrcode{
  5679. UserOrgId: adminInfo.Org.Id,
  5680. Errcode: "自动出库接口报错",
  5681. GoodId: 0,
  5682. Status: 1,
  5683. Ctime: time.Now().Unix(),
  5684. Mtime: 0,
  5685. Count: 0,
  5686. StockCount: 0,
  5687. Creater: creator,
  5688. BatchNumberId: 0,
  5689. WarehouseOutId: 0,
  5690. }
  5691. service.CreateGoodErrcode(goodErrcode)
  5692. }
  5693. //出库数量相加
  5694. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5695. if errss != nil {
  5696. goodErrcode := models.XtGoodErrcode{
  5697. UserOrgId: item.UserOrgId,
  5698. Errcode: "创建剩余库存字段报错",
  5699. GoodId: item.GoodId,
  5700. Status: 1,
  5701. Ctime: time.Now().Unix(),
  5702. Mtime: time.Now().Unix(),
  5703. Count: 0,
  5704. StockCount: 0,
  5705. Creater: item.Creater,
  5706. BatchNumberId: 0,
  5707. WarehouseOutId: 0,
  5708. }
  5709. service.CreateGoodErrcode(goodErrcode)
  5710. }
  5711. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5712. if len(list) == 0 {
  5713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5714. return
  5715. }
  5716. for _, item := range list {
  5717. prepare := models.DialysisBeforePrepare{
  5718. UserOrgId: adminInfo.Org.Id,
  5719. PatientId: patient_id,
  5720. RecordDate: record_time,
  5721. GoodId: item.GoodId,
  5722. GoodTypeId: item.GoodTypeId,
  5723. Count: item.Count,
  5724. Creater: adminInfo.AdminUser.Id,
  5725. Status: 1,
  5726. Ctime: time.Now().Unix(),
  5727. StorehouseId: houseConfig.StorehouseOutInfo,
  5728. }
  5729. //清空准备表数据
  5730. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5731. if errs != nil {
  5732. goodErrcode := models.XtGoodErrcode{
  5733. UserOrgId: adminInfo.Org.Id,
  5734. Errcode: "自动出库清空准备表数据报错",
  5735. GoodId: 0,
  5736. Status: 1,
  5737. Ctime: time.Now().Unix(),
  5738. Mtime: 0,
  5739. Count: 0,
  5740. StockCount: 0,
  5741. Creater: creator,
  5742. BatchNumberId: 0,
  5743. WarehouseOutId: 0,
  5744. }
  5745. service.CreateGoodErrcode(goodErrcode)
  5746. }
  5747. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  5748. if errcodes != nil {
  5749. goodErrcode := models.XtGoodErrcode{
  5750. UserOrgId: adminInfo.Org.Id,
  5751. Errcode: "自动出库创建准备表数据报错",
  5752. GoodId: 0,
  5753. Status: 1,
  5754. Ctime: time.Now().Unix(),
  5755. Mtime: 0,
  5756. Count: 0,
  5757. StockCount: 0,
  5758. Creater: creator,
  5759. BatchNumberId: 0,
  5760. WarehouseOutId: 0,
  5761. }
  5762. service.CreateGoodErrcode(goodErrcode)
  5763. }
  5764. //查询默认仓库
  5765. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5766. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5767. var total_count int64
  5768. for _, it := range stockList {
  5769. total_count += it.StockCount
  5770. }
  5771. //基础库插入数据
  5772. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5773. if errcodes != nil {
  5774. goodErrcode := models.XtGoodErrcode{
  5775. UserOrgId: adminInfo.Org.Id,
  5776. Errcode: "自动出库基础库插入数据报错",
  5777. GoodId: 0,
  5778. Status: 1,
  5779. Ctime: time.Now().Unix(),
  5780. Mtime: 0,
  5781. Count: 0,
  5782. StockCount: 0,
  5783. Creater: creator,
  5784. BatchNumberId: 0,
  5785. WarehouseOutId: 0,
  5786. }
  5787. service.CreateGoodErrcode(goodErrcode)
  5788. }
  5789. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5790. var flush_count int64
  5791. for _, it := range goodList {
  5792. flush_count += it.StockCount
  5793. }
  5794. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5795. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  5796. if errss != nil {
  5797. goodErrcode := models.XtGoodErrcode{
  5798. UserOrgId: item.OrgId,
  5799. Errcode: "自动出库剩余库存更新数据",
  5800. GoodId: item.GoodId,
  5801. Status: 1,
  5802. Ctime: time.Now().Unix(),
  5803. Mtime: 0,
  5804. Count: 0,
  5805. StockCount: 0,
  5806. Creater: creater,
  5807. BatchNumberId: 0,
  5808. WarehouseOutId: 0,
  5809. }
  5810. service.CreateGoodErrcode(goodErrcode)
  5811. }
  5812. }
  5813. }
  5814. }
  5815. c.ServeSuccessJSON(map[string]interface{}{
  5816. "msg": "提交成功",
  5817. "message": "2",
  5818. "good_name": "",
  5819. "specification_name": "",
  5820. })
  5821. return
  5822. }
  5823. if record.IsOpen == 1 {
  5824. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5825. //查询是否有库存
  5826. for _, item := range consumables {
  5827. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5828. if item.Count > warehouse.Count {
  5829. goodErrcode := models.XtGoodErrcode{
  5830. UserOrgId: item.UserOrgId,
  5831. Errcode: "自动出库库存不足",
  5832. GoodId: item.GoodId,
  5833. Status: 1,
  5834. Ctime: time.Now().Unix(),
  5835. Mtime: 0,
  5836. Count: 0,
  5837. StockCount: 0,
  5838. Creater: creator,
  5839. BatchNumberId: warehouse.ID,
  5840. WarehouseOutId: 0,
  5841. }
  5842. service.CreateGoodErrcode(goodErrcode)
  5843. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5844. c.ServeSuccessJSON(map[string]interface{}{
  5845. "message": "1",
  5846. "good_name": goodObj.GoodName,
  5847. "specification_name": goodObj.SpecificationName,
  5848. })
  5849. return
  5850. }
  5851. }
  5852. //查询是否有出库单
  5853. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5854. if err == gorm.ErrRecordNotFound {
  5855. //没有记录,则创建出库单
  5856. timeStr := time.Now().Format("2006-01-02")
  5857. timeArr := strings.Split(timeStr, "-")
  5858. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5859. total = total + 1
  5860. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5861. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5862. number = number + total
  5863. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5864. creater := adminInfo.AdminUser.Id
  5865. warehouseOut := models.WarehouseOut{
  5866. WarehouseOutOrderNumber: warehousing_out_order,
  5867. OperationTime: time.Now().Unix(),
  5868. OrgId: adminInfo.Org.Id,
  5869. Creater: creater,
  5870. Ctime: time.Now().Unix(),
  5871. Status: 1,
  5872. WarehouseOutTime: record_time,
  5873. Dealer: 0,
  5874. Manufacturer: 0,
  5875. Type: 1,
  5876. IsSys: 1,
  5877. StorehouseId: houseConfig.StorehouseOutInfo,
  5878. IsCheck: 1,
  5879. }
  5880. err := service.AddSigleWarehouseOut(&warehouseOut)
  5881. if err != nil {
  5882. goodErrcode := models.XtGoodErrcode{
  5883. UserOrgId: adminInfo.Org.Id,
  5884. Errcode: "创建出库单失败",
  5885. GoodId: 0,
  5886. Status: 1,
  5887. Ctime: time.Now().Unix(),
  5888. Mtime: 0,
  5889. Count: 0,
  5890. StockCount: 0,
  5891. Creater: creator,
  5892. BatchNumberId: 0,
  5893. WarehouseOutId: 0,
  5894. }
  5895. service.CreateGoodErrcode(goodErrcode)
  5896. utils.TraceLog("创建出库单失败 err = %v", err)
  5897. } else {
  5898. for _, item := range consumables {
  5899. //出库
  5900. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  5901. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  5902. if err == nil {
  5903. goodErrcode := models.XtGoodErrcode{
  5904. UserOrgId: adminInfo.Org.Id,
  5905. Errcode: "自动出库接口报错",
  5906. GoodId: 0,
  5907. Status: 1,
  5908. Ctime: time.Now().Unix(),
  5909. Mtime: 0,
  5910. Count: 0,
  5911. StockCount: 0,
  5912. Creater: creator,
  5913. BatchNumberId: 0,
  5914. WarehouseOutId: 0,
  5915. }
  5916. service.CreateGoodErrcode(goodErrcode)
  5917. utils.TraceLog("创建出库单失败 err = %v", err)
  5918. }
  5919. //查询
  5920. //出库数量相加
  5921. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5922. if errs != nil {
  5923. goodErrcode := models.XtGoodErrcode{
  5924. UserOrgId: item.UserOrgId,
  5925. Errcode: "创建剩余库存字段报错",
  5926. GoodId: item.GoodId,
  5927. Status: 1,
  5928. Ctime: time.Now().Unix(),
  5929. Mtime: 0,
  5930. Count: 0,
  5931. StockCount: 0,
  5932. Creater: creater,
  5933. BatchNumberId: 0,
  5934. WarehouseOutId: 0,
  5935. }
  5936. service.CreateGoodErrcode(goodErrcode)
  5937. }
  5938. }
  5939. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5940. if len(list) == 0 {
  5941. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5942. return
  5943. }
  5944. for _, item := range list {
  5945. prepare := models.DialysisBeforePrepare{
  5946. UserOrgId: adminInfo.Org.Id,
  5947. PatientId: patient_id,
  5948. RecordDate: record_time,
  5949. GoodId: item.GoodId,
  5950. GoodTypeId: item.GoodTypeId,
  5951. Count: item.Count,
  5952. Creater: adminInfo.AdminUser.Id,
  5953. Status: 1,
  5954. Ctime: time.Now().Unix(),
  5955. StorehouseId: houseConfig.StorehouseOutInfo,
  5956. }
  5957. //清空准备表数据
  5958. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5959. if err != nil {
  5960. goodErrcode := models.XtGoodErrcode{
  5961. UserOrgId: item.OrgId,
  5962. Errcode: "自动出库清空准备表数据报错",
  5963. GoodId: item.GoodId,
  5964. Status: 1,
  5965. Ctime: time.Now().Unix(),
  5966. Mtime: 0,
  5967. Count: 0,
  5968. StockCount: 0,
  5969. Creater: creater,
  5970. BatchNumberId: 0,
  5971. WarehouseOutId: 0,
  5972. }
  5973. service.CreateGoodErrcode(goodErrcode)
  5974. }
  5975. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  5976. if errs != nil {
  5977. goodErrcode := models.XtGoodErrcode{
  5978. UserOrgId: item.OrgId,
  5979. Errcode: "自动出库创建准备表数据报错",
  5980. GoodId: item.GoodId,
  5981. Status: 1,
  5982. Ctime: time.Now().Unix(),
  5983. Mtime: 0,
  5984. Count: 0,
  5985. StockCount: 0,
  5986. Creater: creater,
  5987. BatchNumberId: 0,
  5988. WarehouseOutId: 0,
  5989. }
  5990. service.CreateGoodErrcode(goodErrcode)
  5991. }
  5992. //查询默认仓库
  5993. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5994. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5995. var total_count int64
  5996. for _, it := range stockList {
  5997. total_count += it.StockCount
  5998. }
  5999. //基础库插入数据
  6000. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6001. if errcodes != nil {
  6002. goodErrcode := models.XtGoodErrcode{
  6003. UserOrgId: item.OrgId,
  6004. Errcode: "自动出库基础库插入数据",
  6005. GoodId: item.GoodId,
  6006. Status: 1,
  6007. Ctime: time.Now().Unix(),
  6008. Mtime: 0,
  6009. Count: 0,
  6010. StockCount: 0,
  6011. Creater: creater,
  6012. BatchNumberId: 0,
  6013. WarehouseOutId: 0,
  6014. }
  6015. service.CreateGoodErrcode(goodErrcode)
  6016. }
  6017. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6018. var flush_count int64
  6019. for _, it := range goodList {
  6020. flush_count += it.StockCount
  6021. }
  6022. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6023. if errsss != nil {
  6024. goodErrcode := models.XtGoodErrcode{
  6025. UserOrgId: item.OrgId,
  6026. Errcode: "自动出库剩余库存更新数据",
  6027. GoodId: item.GoodId,
  6028. Status: 1,
  6029. Ctime: time.Now().Unix(),
  6030. Mtime: 0,
  6031. Count: 0,
  6032. StockCount: 0,
  6033. Creater: creater,
  6034. BatchNumberId: 0,
  6035. WarehouseOutId: 0,
  6036. }
  6037. service.CreateGoodErrcode(goodErrcode)
  6038. }
  6039. }
  6040. }
  6041. //
  6042. } else if err == nil {
  6043. for _, item := range consumables {
  6044. //出库
  6045. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6046. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6047. if err != nil {
  6048. goodErrcode := models.XtGoodErrcode{
  6049. UserOrgId: adminInfo.Org.Id,
  6050. Errcode: "自动出库接口报错",
  6051. GoodId: 0,
  6052. Status: 1,
  6053. Ctime: time.Now().Unix(),
  6054. Mtime: 0,
  6055. Count: 0,
  6056. StockCount: 0,
  6057. Creater: creator,
  6058. BatchNumberId: 0,
  6059. WarehouseOutId: 0,
  6060. }
  6061. service.CreateGoodErrcode(goodErrcode)
  6062. }
  6063. //出库数量相加
  6064. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6065. if errss != nil {
  6066. goodErrcode := models.XtGoodErrcode{
  6067. UserOrgId: item.UserOrgId,
  6068. Errcode: "创建剩余库存字段报错",
  6069. GoodId: item.GoodId,
  6070. Status: 1,
  6071. Ctime: time.Now().Unix(),
  6072. Mtime: time.Now().Unix(),
  6073. Count: 0,
  6074. StockCount: 0,
  6075. Creater: item.Creater,
  6076. BatchNumberId: 0,
  6077. WarehouseOutId: 0,
  6078. }
  6079. service.CreateGoodErrcode(goodErrcode)
  6080. }
  6081. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6082. if len(list) == 0 {
  6083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6084. return
  6085. }
  6086. for _, item := range list {
  6087. prepare := models.DialysisBeforePrepare{
  6088. UserOrgId: adminInfo.Org.Id,
  6089. PatientId: patient_id,
  6090. RecordDate: record_time,
  6091. GoodId: item.GoodId,
  6092. GoodTypeId: item.GoodTypeId,
  6093. Count: item.Count,
  6094. Creater: adminInfo.AdminUser.Id,
  6095. Status: 1,
  6096. Ctime: time.Now().Unix(),
  6097. StorehouseId: houseConfig.StorehouseOutInfo,
  6098. }
  6099. //清空准备表数据
  6100. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6101. if errs != nil {
  6102. goodErrcode := models.XtGoodErrcode{
  6103. UserOrgId: adminInfo.Org.Id,
  6104. Errcode: "自动出库清空准备表数据报错",
  6105. GoodId: 0,
  6106. Status: 1,
  6107. Ctime: time.Now().Unix(),
  6108. Mtime: 0,
  6109. Count: 0,
  6110. StockCount: 0,
  6111. Creater: creator,
  6112. BatchNumberId: 0,
  6113. WarehouseOutId: 0,
  6114. }
  6115. service.CreateGoodErrcode(goodErrcode)
  6116. }
  6117. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6118. if errcodes != nil {
  6119. goodErrcode := models.XtGoodErrcode{
  6120. UserOrgId: adminInfo.Org.Id,
  6121. Errcode: "自动出库创建准备表数据报错",
  6122. GoodId: 0,
  6123. Status: 1,
  6124. Ctime: time.Now().Unix(),
  6125. Mtime: 0,
  6126. Count: 0,
  6127. StockCount: 0,
  6128. Creater: creator,
  6129. BatchNumberId: 0,
  6130. WarehouseOutId: 0,
  6131. }
  6132. service.CreateGoodErrcode(goodErrcode)
  6133. }
  6134. //查询默认仓库
  6135. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6136. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6137. var total_count int64
  6138. for _, it := range stockList {
  6139. total_count += it.StockCount
  6140. }
  6141. //基础库插入数据
  6142. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6143. if errcodes != nil {
  6144. goodErrcode := models.XtGoodErrcode{
  6145. UserOrgId: adminInfo.Org.Id,
  6146. Errcode: "自动出库基础库插入数据报错",
  6147. GoodId: 0,
  6148. Status: 1,
  6149. Ctime: time.Now().Unix(),
  6150. Mtime: 0,
  6151. Count: 0,
  6152. StockCount: 0,
  6153. Creater: creator,
  6154. BatchNumberId: 0,
  6155. WarehouseOutId: 0,
  6156. }
  6157. service.CreateGoodErrcode(goodErrcode)
  6158. }
  6159. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6160. var flush_count int64
  6161. for _, it := range goodList {
  6162. flush_count += it.StockCount
  6163. }
  6164. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6165. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6166. if errss != nil {
  6167. goodErrcode := models.XtGoodErrcode{
  6168. UserOrgId: item.OrgId,
  6169. Errcode: "自动出库剩余库存更新数据",
  6170. GoodId: item.GoodId,
  6171. Status: 1,
  6172. Ctime: time.Now().Unix(),
  6173. Mtime: 0,
  6174. Count: 0,
  6175. StockCount: 0,
  6176. Creater: creater,
  6177. BatchNumberId: 0,
  6178. WarehouseOutId: 0,
  6179. }
  6180. service.CreateGoodErrcode(goodErrcode)
  6181. }
  6182. }
  6183. }
  6184. }
  6185. c.ServeSuccessJSON(map[string]interface{}{
  6186. "msg": "提交成功",
  6187. "message": "2",
  6188. "good_name": "",
  6189. "specification_name": "",
  6190. })
  6191. return
  6192. } else {
  6193. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  6194. return
  6195. }
  6196. }
  6197. func (c *DialysisAPIController) EditConsumables() {
  6198. patient_id, _ := c.GetInt64("patient_id", 0)
  6199. record_date := c.GetString("record_time")
  6200. if patient_id <= 0 {
  6201. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6202. return
  6203. }
  6204. adminInfo := c.GetMobileAdminUserInfo()
  6205. timeLayout := "2006-01-02"
  6206. loc, _ := time.LoadLocation("Local")
  6207. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6208. record_time := theRecordTime.Unix()
  6209. // 查询信息规挡的设置天数
  6210. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6211. if infor.ID > 0 && infor.WeekDay > 0 {
  6212. var cha_time int64
  6213. timeNowStr := time.Now().Format("2006-01-02")
  6214. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6215. //今日的日期减去设置的日期
  6216. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6217. if cha_time >= record_time {
  6218. //查询审核是否允许
  6219. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6220. //申请状态不允许的情况 拒绝修改
  6221. if infor.ApplicationStatus != 1 {
  6222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6223. return
  6224. }
  6225. }
  6226. }
  6227. dataBody := make(map[string]interface{}, 0)
  6228. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6229. if err != nil {
  6230. utils.ErrorLog(err.Error())
  6231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6232. return
  6233. }
  6234. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6235. var beforePrepares []*models.DialysisBeforePrepareGoods
  6236. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6237. var cancelbefor []*models.DialysisBeforePrepareGoods
  6238. var outbefor []*models.DialysisBeforePrepareGoods
  6239. //判断是否开启自动出库
  6240. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6241. if record.IsOpen == 1 {
  6242. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6243. goods, _ := dataBody["goods"].([]interface{})
  6244. if len(goods) > 0 {
  6245. for _, item := range goods {
  6246. items := item.(map[string]interface{})
  6247. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6248. utils.ErrorLog("good_id")
  6249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6250. return
  6251. }
  6252. good_id := int64(items["good_id"].(float64))
  6253. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6254. utils.ErrorLog("good_type_id")
  6255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6256. return
  6257. }
  6258. good_type_id := int64(items["good_type_id"].(float64))
  6259. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6260. utils.ErrorLog("count")
  6261. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6262. return
  6263. }
  6264. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6265. commdity_code := items["commdity_code"].(string)
  6266. fmt.Println(commdity_code)
  6267. prepareGoods := &models.DialysisBeforePrepareGoods{
  6268. GoodTypeId: good_type_id,
  6269. GoodId: good_id,
  6270. Count: count,
  6271. StorehouseId: houseConfig.StorehouseOutInfo,
  6272. }
  6273. beforePrepares = append(beforePrepares, prepareGoods)
  6274. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  6275. GoodTypeId: good_type_id,
  6276. GoodId: good_id,
  6277. Count: count,
  6278. StorehouseId: houseConfig.StorehouseOutInfo,
  6279. }
  6280. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  6281. }
  6282. for _, item := range beforePrepares {
  6283. //1.查看该患者该耗材型号最后一次出库数量
  6284. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6285. //判断当前出库数量和最后一次出库数量的大小
  6286. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  6287. if item.Count < goodInfo.Count {
  6288. cancelbefor = append(cancelbefor, item)
  6289. }
  6290. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6291. if item.Count > goodInfo.Count {
  6292. outbefor = append(outbefor, item)
  6293. }
  6294. //处理编辑耗材新增不了的问题
  6295. if goodInfo.Count == item.Count {
  6296. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  6297. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  6298. }
  6299. }
  6300. if len(cancelbefor) > 0 {
  6301. //退库
  6302. for _, item := range cancelbefor {
  6303. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6304. creater := adminInfo.AdminUser.Id
  6305. //查询该患者当天已经出库的耗材信息
  6306. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  6307. var delete_count int64 = 0
  6308. delete_count = warehouseOutInfos.Count - item.Count
  6309. //增加库存数量
  6310. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  6311. //减少实际出库库存数量
  6312. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  6313. // 删除出库完成后,要增加对应批次的库存数量
  6314. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  6315. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6316. //更新剩余库存
  6317. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6318. var flush_count int64
  6319. for _, it := range goodListOne {
  6320. flush_count += it.StockCount
  6321. }
  6322. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6323. //查询剩余库存
  6324. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6325. var sum_count int64
  6326. for _, item := range goodList {
  6327. sum_count += item.StockCount
  6328. }
  6329. // 在出库记录表里记录退库详情
  6330. warehouseOutInfo := &models.WarehouseOutInfo{
  6331. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6332. WarehouseOutId: warehouseOut.ID,
  6333. Status: 1,
  6334. Ctime: time.Now().Unix(),
  6335. OrgId: adminInfo.Org.Id,
  6336. Type: 1,
  6337. IsSys: 1,
  6338. SysRecordTime: record_time,
  6339. GoodTypeId: item.GoodTypeId,
  6340. GoodId: item.GoodId,
  6341. PatientId: patient_id,
  6342. ConsumableType: 2,
  6343. StorehouseId: houseConfig.StorehouseOutInfo,
  6344. IsCheck: 1,
  6345. OverCount: sum_count,
  6346. }
  6347. warehouseOutInfo.Count = item.Count
  6348. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  6349. warehouseOutInfo.Price = stockInInfo.Price
  6350. warehouseOutInfo.Dealer = stockInInfo.Dealer
  6351. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  6352. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  6353. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  6354. warehouseOutInfo.Number = warehouseOutInfos.Number
  6355. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  6356. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  6357. //查找当天是否存在出库记录
  6358. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  6359. if errcod == gorm.ErrRecordNotFound {
  6360. service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  6361. //插入详情明细表
  6362. stockFlow := models.VmStockFlow{
  6363. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6364. WarehouseOutId: warehouseOut.ID,
  6365. GoodId: item.GoodId,
  6366. Number: warehouseOutInfos.Number,
  6367. ProductDate: stockInInfo.ProductDate,
  6368. ExpireDate: stockInInfo.ExpiryDate,
  6369. Count: item.Count,
  6370. Price: stockInInfo.Price,
  6371. Status: 1,
  6372. Ctime: record_time,
  6373. UserOrgId: adminInfo.Org.Id,
  6374. Manufacturer: stockInInfo.Manufacturer,
  6375. Dealer: stockInInfo.Dealer,
  6376. LicenseNumber: stockInInfo.LicenseNumber,
  6377. IsEdit: 2,
  6378. Creator: creater,
  6379. SystemTime: record_time,
  6380. ConsumableType: 3,
  6381. WarehousingDetailId: 0,
  6382. IsSys: 1,
  6383. UpdateCreator: creater,
  6384. PatientId: patient_id,
  6385. StorehouseId: houseConfig.StorehouseOutInfo,
  6386. }
  6387. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  6388. if errflow == gorm.ErrRecordNotFound {
  6389. //创建流水表
  6390. err := service.CreateStockFlowOne(stockFlow)
  6391. fmt.Println("err", err)
  6392. } else if errflow == nil {
  6393. //插入详情明细表
  6394. stockFlow := models.VmStockFlow{
  6395. ID: exsit.ID,
  6396. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  6397. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6398. WarehouseOutId: warehouseOut.ID,
  6399. GoodId: item.GoodId,
  6400. Number: warehouseOutInfos.Number,
  6401. ProductDate: stockInInfo.ProductDate,
  6402. ExpireDate: stockInInfo.ExpiryDate,
  6403. Count: exsit.Count - delete_count,
  6404. Price: stockInInfo.Price,
  6405. Status: 1,
  6406. Ctime: record_time,
  6407. UserOrgId: adminInfo.Org.Id,
  6408. Manufacturer: stockInInfo.Manufacturer,
  6409. Dealer: stockInInfo.Dealer,
  6410. LicenseNumber: stockInInfo.LicenseNumber,
  6411. IsEdit: 2,
  6412. Creator: creater,
  6413. SystemTime: record_time,
  6414. ConsumableType: 3,
  6415. WarehousingDetailId: 0,
  6416. IsSys: 1,
  6417. UpdateCreator: creater,
  6418. PatientId: patient_id,
  6419. StorehouseId: houseConfig.StorehouseOutInfo,
  6420. }
  6421. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  6422. }
  6423. } else if errcod == nil {
  6424. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  6425. //查询剩余库存
  6426. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6427. var sum_count int64
  6428. for _, item := range goodList {
  6429. sum_count += item.StockCount
  6430. }
  6431. //创建退库单,生成退库数据
  6432. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6433. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  6434. operation_time := time.Now().Unix()
  6435. creater := adminInfo.AdminUser.Id
  6436. //创建退库单
  6437. timeStr := time.Now().Format("2006-01-02")
  6438. timeArr := strings.Split(timeStr, "-")
  6439. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  6440. total = total + 1
  6441. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6442. cancelStock := models.CancelStock{
  6443. OrderNumber: orderNumber,
  6444. OperaTime: operation_time,
  6445. OrgId: adminInfo.Org.Id,
  6446. Creater: creater,
  6447. Ctime: time.Now().Unix(),
  6448. Status: 1,
  6449. ReturnTime: record_time,
  6450. Type: 1,
  6451. StorehouseId: houseConfig.StorehouseOutInfo,
  6452. IsCheck: 1,
  6453. }
  6454. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  6455. if msgerrkonde == gorm.ErrRecordNotFound {
  6456. service.AddSigleCancelStock(&cancelStock)
  6457. }
  6458. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  6459. //查询是否有出库
  6460. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  6461. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6462. deaerler, _ := service.GetDealerById(info.Dealer)
  6463. if info.ID > 0 {
  6464. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  6465. cancelStockInfo := models.CancelStockInfo{
  6466. GoodId: item.GoodId,
  6467. CancelStockId: cancel.ID,
  6468. GoodTypeId: good.GoodTypeId,
  6469. Count: delete_count,
  6470. Price: info.Price,
  6471. Total: 0,
  6472. ProductDate: info.ProductDate,
  6473. ExpiryDate: info.ExpiryDate,
  6474. Ctime: time.Now().Unix(),
  6475. Status: 1,
  6476. OrgId: adminInfo.Org.Id,
  6477. OrderNumber: cancel.OrderNumber,
  6478. Type: 0,
  6479. Dealer: deaerler.DealerName,
  6480. Manufacturer: manufacturer.ManufacturerName,
  6481. Number: info.Number,
  6482. RegisterAccount: "",
  6483. Remark: "",
  6484. WarehouseInfoId: info.WarehouseInfotId,
  6485. PatientId: info.PatientId,
  6486. RecordDate: info.SysRecordTime,
  6487. StorehouseId: houseConfig.StorehouseOutInfo,
  6488. IsCheck: 1,
  6489. }
  6490. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6491. //退库数量增加
  6492. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  6493. //查询剩余库存
  6494. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6495. var over_count int64
  6496. for _, it := range goodList {
  6497. over_count += it.StockCount
  6498. }
  6499. flow := models.VmStockFlow{
  6500. WarehousingId: info.WarehouseInfotId,
  6501. GoodId: item.GoodId,
  6502. Number: info.Number,
  6503. LicenseNumber: info.LicenseNumber,
  6504. Count: delete_count,
  6505. UserOrgId: adminInfo.Org.Id,
  6506. PatientId: patient_id,
  6507. SystemTime: info.SysRecordTime,
  6508. ConsumableType: 7,
  6509. IsSys: 0,
  6510. WarehousingOrder: "",
  6511. WarehouseOutId: info.WarehouseOutId,
  6512. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6513. IsEdit: 0,
  6514. CancelStockId: cancel.ID,
  6515. CancelOrderNumber: cancel.OrderNumber,
  6516. Manufacturer: manufacturer.ID,
  6517. Dealer: 0,
  6518. Creator: adminInfo.AdminUser.Id,
  6519. UpdateCreator: 0,
  6520. Status: 1,
  6521. Ctime: record_time,
  6522. Mtime: 0,
  6523. Price: info.Price,
  6524. WarehousingDetailId: info.WarehouseInfotId,
  6525. WarehouseOutDetailId: info.ID,
  6526. CancelOutDetailId: cancelInfo.ID,
  6527. ProductDate: info.ProductDate,
  6528. ExpireDate: info.ExpiryDate,
  6529. StorehouseId: houseConfig.StorehouseOutInfo,
  6530. OverCount: over_count,
  6531. }
  6532. service.CreateStockFlowOne(flow)
  6533. }
  6534. }
  6535. //更改自动出库的表格
  6536. details := models.BloodAutomaticReduceDetail{
  6537. WarehouseOutId: warehouseOutInfo.ID,
  6538. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  6539. PatientId: patient_id,
  6540. Ctime: time.Now().Unix(),
  6541. Mtime: time.Now().Unix(),
  6542. Status: 1,
  6543. RecordTime: record_time,
  6544. OrgId: adminInfo.Org.Id,
  6545. GoodId: item.GoodId,
  6546. GoodTypeId: item.GoodTypeId,
  6547. Count: item.Count,
  6548. StorehouseId: houseConfig.StorehouseOutInfo,
  6549. }
  6550. //查询当天耗材是否已经存在数据
  6551. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6552. if errcode == gorm.ErrRecordNotFound {
  6553. service.CreateAutoReduceRecord(&details)
  6554. } else if errcode == nil {
  6555. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6556. service.CreateAutoReduceRecord(&details)
  6557. }
  6558. //查询默认仓库
  6559. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6560. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6561. var total_count int64
  6562. for _, it := range stockList {
  6563. total_count += it.StockCount
  6564. }
  6565. //基础库插入数据
  6566. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6567. }
  6568. }
  6569. if len(outbefor) > 0 {
  6570. //出库
  6571. for _, item := range outbefor {
  6572. var last_total int64
  6573. //1.查看该患者该耗材型号最后一次出库数量
  6574. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6575. //计算当前出库和最后一次出库数据相差数据
  6576. last_total = item.Count - goodInfoOne.Count
  6577. //查询该耗材的总库存
  6578. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  6579. // 如果库存差大于剩余库存则提示库存不足
  6580. if last_total > wareinfo.StockCount {
  6581. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6582. c.ServeSuccessJSON(map[string]interface{}{
  6583. "message": "1",
  6584. "good_name": goodObj.GoodName,
  6585. "specification_name": goodObj.SpecificationName,
  6586. })
  6587. return
  6588. } else {
  6589. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6590. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6591. if err == gorm.ErrRecordNotFound {
  6592. //没有记录,则创建出库单
  6593. timeStr := time.Now().Format("2006-01-02")
  6594. timeArr := strings.Split(timeStr, "-")
  6595. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6596. total = total + 1
  6597. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6598. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6599. number = number + total
  6600. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6601. warehouseOut := models.WarehouseOut{
  6602. WarehouseOutOrderNumber: warehousing_out_order,
  6603. OperationTime: time.Now().Unix(),
  6604. OrgId: adminInfo.Org.Id,
  6605. Creater: adminInfo.AdminUser.Id,
  6606. Ctime: time.Now().Unix(),
  6607. Status: 1,
  6608. WarehouseOutTime: record_time,
  6609. Dealer: 0,
  6610. Manufacturer: 0,
  6611. Type: 1,
  6612. IsSys: 1,
  6613. StorehouseId: houseConfig.StorehouseOutInfo,
  6614. IsCheck: 1,
  6615. }
  6616. service.AddSigleWarehouseOut(&warehouseOut)
  6617. }
  6618. //出库
  6619. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  6620. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6621. //1.查看该患者该耗材型号最后一次出库数量
  6622. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6623. prepare := models.DialysisBeforePrepare{
  6624. UserOrgId: adminInfo.Org.Id,
  6625. PatientId: patient_id,
  6626. RecordDate: record_time,
  6627. GoodId: item.GoodId,
  6628. GoodTypeId: item.GoodTypeId,
  6629. Count: item.Count - goodInfoTwo.Count,
  6630. Ctime: time.Now().Unix(),
  6631. Mtime: 0,
  6632. Creater: adminInfo.AdminUser.Id,
  6633. Modifier: adminInfo.AdminUser.Id,
  6634. Status: 1,
  6635. CommdityCode: "",
  6636. NewCount: 0,
  6637. ProjectId: 0,
  6638. StorehouseId: houseConfig.StorehouseOutInfo,
  6639. }
  6640. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  6641. //增加出库数量
  6642. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  6643. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6644. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6645. var total_count int64
  6646. for _, it := range stockList {
  6647. total_count += it.StockCount
  6648. }
  6649. //基础库插入数据
  6650. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6651. //剩余库存
  6652. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6653. var flush_count int64
  6654. for _, it := range goodList {
  6655. flush_count += it.StockCount
  6656. }
  6657. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6658. }
  6659. }
  6660. }
  6661. //查询今日出库数据
  6662. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6663. for _, it := range list {
  6664. prepare := models.DialysisBeforePrepare{
  6665. UserOrgId: it.OrgId,
  6666. PatientId: patient_id,
  6667. RecordDate: it.RecordTime,
  6668. GoodId: it.GoodId,
  6669. GoodTypeId: it.GoodTypeId,
  6670. Count: it.Count,
  6671. Ctime: time.Now().Unix(),
  6672. Creater: adminInfo.AdminUser.Id,
  6673. Status: 1,
  6674. StorehouseId: houseConfig.StorehouseOutInfo,
  6675. ProjectId: it.ProjectId,
  6676. }
  6677. //删除准备表数据
  6678. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  6679. service.CreateDialysisBeforePrepareOne(&prepare)
  6680. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6681. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6682. var total_count int64
  6683. for _, it := range stockList {
  6684. total_count += it.StockCount
  6685. }
  6686. //基础库插入数据
  6687. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  6688. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  6689. var flush_count int64
  6690. for _, it := range goodList {
  6691. flush_count += it.StockCount
  6692. }
  6693. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  6694. }
  6695. }
  6696. }
  6697. //更新自动出库的地方
  6698. var errs error
  6699. if errs == nil {
  6700. c.ServeSuccessJSON(map[string]interface{}{
  6701. "msg": "修改成功",
  6702. "message": "2",
  6703. "good_name": "",
  6704. "specification_name": "",
  6705. })
  6706. return
  6707. } else {
  6708. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6709. return
  6710. }
  6711. }
  6712. }
  6713. func (c *DialysisAPIController) GetDialysisGoods() {
  6714. schedualDate := c.GetString("schedule_date")
  6715. schedule_type, _ := c.GetInt64("schedule_type")
  6716. partition_id, _ := c.GetInt64("partition_id")
  6717. page, _ := c.GetInt("page")
  6718. patient_id, _ := c.GetInt64("patient_id")
  6719. schedualEndDate := int64(0)
  6720. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  6721. if parseDateErr != nil && len(schedualDate) != 0 {
  6722. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6723. return
  6724. }
  6725. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  6726. if parseDateErr != nil && len(schedualDate) != 0 {
  6727. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6728. return
  6729. }
  6730. schedualEndDate = endDate.Unix()
  6731. adminUser := c.GetMobileAdminUserInfo()
  6732. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  6733. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  6734. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  6735. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  6736. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  6737. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  6738. //获取当天该病人的透析处方
  6739. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  6740. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  6741. if err == gorm.ErrRecordNotFound {
  6742. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  6743. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  6744. if patient_id != 0 {
  6745. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  6746. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  6747. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  6748. //获取患者总的出库数据
  6749. item.LastAutomaticReduceDetail = goodUser
  6750. item.LastDialysisBeforePrepare = lastGoodUserDetial
  6751. item.Project = project
  6752. }
  6753. }
  6754. c.ServeSuccessJSON(map[string]interface{}{
  6755. "dialysis_goods": dialysisGoods,
  6756. "good_type": goodTypes,
  6757. "total": total,
  6758. "prescribe": prescribe,
  6759. "good_info": good_info,
  6760. "warehouseOutList": warehouseOutList,
  6761. "config": config,
  6762. "outConfig": outConfig,
  6763. "settleConfig": settleConfig,
  6764. })
  6765. return
  6766. } else if err == nil {
  6767. //获取当天排班的每个患者的库存使用情况
  6768. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  6769. //获取患者总的出库数据
  6770. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  6771. if patient_id != 0 {
  6772. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  6773. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  6774. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  6775. item.Project = project
  6776. item.LastAutomaticReduceDetail = goodUser
  6777. item.LastDialysisBeforePrepare = lastGoodUserDetial
  6778. }
  6779. }
  6780. if err == nil {
  6781. c.ServeSuccessJSON(map[string]interface{}{
  6782. "dialysis_goods": dialysisGoods,
  6783. "good_type": goodTypes,
  6784. "total": total,
  6785. "prescribe": prescribe,
  6786. "good_info": good_info,
  6787. "project": project,
  6788. "warehouseOutList": warehouseOutList,
  6789. "config": config,
  6790. "outConfig": outConfig,
  6791. "settleConfig": settleConfig,
  6792. })
  6793. return
  6794. } else {
  6795. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6796. return
  6797. }
  6798. } else if err != nil {
  6799. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6800. return
  6801. }
  6802. }
  6803. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  6804. start_time := c.GetString("start_time")
  6805. end_time := c.GetString("end_time")
  6806. timeLayout := "2006-01-02"
  6807. loc, _ := time.LoadLocation("Local")
  6808. var theStartTime int64
  6809. if len(start_time) > 0 {
  6810. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6811. if err != nil {
  6812. utils.ErrorLog(err.Error())
  6813. }
  6814. theStartTime = theTime.Unix()
  6815. }
  6816. var theEndtTime int64
  6817. if len(end_time) > 0 {
  6818. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6819. if err != nil {
  6820. utils.ErrorLog(err.Error())
  6821. }
  6822. theEndtTime = theTime.Unix()
  6823. }
  6824. adminUser := c.GetMobileAdminUserInfo()
  6825. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  6826. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  6827. if err == nil {
  6828. c.ServeSuccessJSON(map[string]interface{}{
  6829. "stock_out": outInfo,
  6830. "stockCount": stockCount,
  6831. })
  6832. return
  6833. } else {
  6834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6835. return
  6836. }
  6837. }
  6838. func (c *DialysisAPIController) GetStockInGoodInfo() {
  6839. patient_id, _ := c.GetInt64("patient_id", 0)
  6840. record_time := c.GetString("record_time")
  6841. adminUser := c.GetMobileAdminUserInfo()
  6842. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  6843. if parseDateErr != nil && len(record_time) != 0 {
  6844. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6845. return
  6846. }
  6847. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  6848. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  6849. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  6850. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  6851. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  6852. //获取今日患者的透析处方参数
  6853. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  6854. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  6855. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  6856. c.ServeSuccessJSON(map[string]interface{}{
  6857. "good_type": goodTypes,
  6858. "good_user": goodUser,
  6859. "good_info": good_info,
  6860. "last_good_user": lastGoodUserDetial,
  6861. "project": project,
  6862. "prescription": prescribe,
  6863. "outInfo": outInfo,
  6864. "configs": configs,
  6865. })
  6866. return
  6867. }
  6868. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  6869. patient_id, _ := c.GetInt64("patient_id", 0)
  6870. record_date := c.GetString("record_time")
  6871. timeLayout := "2006-01-02"
  6872. loc, _ := time.LoadLocation("Local")
  6873. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6874. record_time := theRecordTime.Unix()
  6875. adminInfo := c.GetMobileAdminUserInfo()
  6876. dataBody := make(map[string]interface{}, 0)
  6877. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6878. if err != nil {
  6879. utils.ErrorLog(err.Error())
  6880. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6881. return
  6882. }
  6883. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6884. var beforePrepares []*models.DialysisBeforePrepareGoods
  6885. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6886. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6887. goods, _ := dataBody["goods"].([]interface{})
  6888. if len(goods) > 0 {
  6889. for _, item := range goods {
  6890. items := item.(map[string]interface{})
  6891. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6892. utils.ErrorLog("good_id")
  6893. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6894. return
  6895. }
  6896. good_id := int64(items["good_id"].(float64))
  6897. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6898. utils.ErrorLog("good_type_id")
  6899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6900. return
  6901. }
  6902. good_type_id := int64(items["good_type_id"].(float64))
  6903. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6904. utils.ErrorLog("count")
  6905. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6906. return
  6907. }
  6908. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6909. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  6910. utils.ErrorLog("project_id")
  6911. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6912. return
  6913. }
  6914. project_id := int64(items["project_id"].(float64))
  6915. new_count := int64(items["new_count"].(float64))
  6916. old_count := int64(items["old_count"].(float64))
  6917. prepare := &models.DialysisBeforePrepareGoods{
  6918. GoodId: good_id,
  6919. GoodTypeId: good_type_id,
  6920. Count: count,
  6921. ProjectId: project_id,
  6922. StorehouseId: houseConfig.StorehouseOutInfo,
  6923. NewCount: new_count,
  6924. OldCount: old_count,
  6925. }
  6926. beforePrepares = append(beforePrepares, prepare)
  6927. newPrepare := &models.NewDialysisBeforePrepareGoods{
  6928. GoodId: good_id,
  6929. GoodTypeId: good_type_id,
  6930. Count: count,
  6931. ProjectId: project_id,
  6932. StorehouseId: houseConfig.StorehouseOutInfo,
  6933. NewCount: new_count,
  6934. OldCount: old_count,
  6935. }
  6936. newBeforePrepares = append(newBeforePrepares, newPrepare)
  6937. }
  6938. }
  6939. }
  6940. //查询是否有库存
  6941. for _, item := range beforePrepares {
  6942. if item.NewCount > 0 {
  6943. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6944. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  6945. if item.Count > warehouse.Count {
  6946. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6947. c.ServeSuccessJSON(map[string]interface{}{
  6948. "message": "1",
  6949. "good_name": goodObj.GoodName,
  6950. "specification_name": goodObj.SpecificationName,
  6951. })
  6952. return
  6953. }
  6954. }
  6955. }
  6956. // 查询信息规挡的设置天数
  6957. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6958. if infor.ID > 0 && infor.WeekDay > 0 {
  6959. var cha_time int64
  6960. timeNowStr := time.Now().Format("2006-01-02")
  6961. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6962. //今日的日期减去设置的日期
  6963. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6964. if cha_time >= record_time {
  6965. //查询审核是否允许
  6966. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6967. //申请状态不允许的情况 拒绝修改
  6968. if infor.ApplicationStatus != 1 {
  6969. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6970. return
  6971. }
  6972. }
  6973. }
  6974. //出库逻辑
  6975. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  6976. if err != nil {
  6977. utils.ErrorLog(err.Error())
  6978. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6979. return
  6980. }
  6981. finish := models.XtDialysisFinish{
  6982. IsFinish: 1,
  6983. UserOrgId: adminInfo.Org.Id,
  6984. Status: 1,
  6985. Ctime: time.Now().Unix(),
  6986. Mtime: 0,
  6987. Module: 11,
  6988. RecordDate: record_time,
  6989. Sourse: 1,
  6990. PatientId: patient_id,
  6991. }
  6992. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  6993. if dialysisFinish.ID == 0 {
  6994. service.CreateDialysisFinish(finish)
  6995. }
  6996. //查询当天出库的数据
  6997. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6998. for _, item := range list {
  6999. prepare := models.DialysisBeforePrepare{
  7000. UserOrgId: item.OrgId,
  7001. PatientId: item.PatientId,
  7002. RecordDate: item.RecordTime,
  7003. GoodId: item.GoodId,
  7004. GoodTypeId: item.GoodTypeId,
  7005. Count: item.Count,
  7006. Creater: adminInfo.AdminUser.Id,
  7007. Status: 1,
  7008. Ctime: time.Now().Unix(),
  7009. ProjectId: item.ProjectId,
  7010. StorehouseId: houseConfig.StorehouseOutInfo,
  7011. }
  7012. //清空准备表的数据
  7013. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7014. //插入准备表数据
  7015. service.CreateDialysisBeforePrepareOne(&prepare)
  7016. //查询默认仓库
  7017. //查询默认仓库
  7018. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7019. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7020. var total_count int64
  7021. for _, it := range stockList {
  7022. total_count += it.StockCount
  7023. }
  7024. //基础库插入数据
  7025. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7026. ////更新剩余库存
  7027. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7028. var flush_count int64
  7029. for _, it := range goodList {
  7030. flush_count += it.StockCount
  7031. }
  7032. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7033. if errs != nil {
  7034. goodErrcode := models.XtGoodErrcode{
  7035. UserOrgId: item.OrgId,
  7036. Errcode: "手动出库更新剩余出库失败",
  7037. GoodId: item.GoodId,
  7038. Status: 1,
  7039. Ctime: time.Now().Unix(),
  7040. Mtime: 0,
  7041. Count: 0,
  7042. StockCount: 0,
  7043. Creater: adminInfo.AdminUser.Id,
  7044. BatchNumberId: 0,
  7045. WarehouseOutId: 0,
  7046. }
  7047. service.CreateGoodErrcode(goodErrcode)
  7048. }
  7049. }
  7050. //更新自动出库的地方
  7051. var errs error
  7052. if errs == nil {
  7053. c.ServeSuccessJSON(map[string]interface{}{
  7054. "msg": "修改成功",
  7055. "message": "2",
  7056. "good_name": "",
  7057. "specification_name": "",
  7058. })
  7059. return
  7060. } else {
  7061. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7062. return
  7063. }
  7064. }
  7065. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7066. newArr = make([]*models.DialysisBeforePrepare, 0)
  7067. for i := 0; i < len(arr); i++ {
  7068. repeat := false
  7069. for j := i + 1; j < len(arr); j++ {
  7070. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  7071. repeat = true
  7072. break
  7073. }
  7074. }
  7075. if !repeat {
  7076. newArr = append(newArr, arr[i])
  7077. }
  7078. }
  7079. return
  7080. }
  7081. func (c *DialysisAPIController) GetAllDrug() {
  7082. patient_id, _ := c.GetInt64("patient_id", 0)
  7083. adminInfo := c.GetMobileAdminUserInfo()
  7084. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7085. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  7086. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  7087. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  7088. c.ServeSuccessJSON(map[string]interface{}{
  7089. "base_drug_config": drugStockConfig,
  7090. "private_drug_config": privateDrugConfig,
  7091. "base_drug_list": drugList,
  7092. "private_drug_list": privateDrugList,
  7093. })
  7094. }
  7095. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7096. newArr = make([]*models.DialysisBeforePrepare, 0)
  7097. for i := 0; i < len(arr); i++ {
  7098. repeat := false
  7099. for j := i + 1; j < len(arr); j++ {
  7100. if arr[i].GoodId == arr[j].GoodId {
  7101. repeat = true
  7102. break
  7103. }
  7104. }
  7105. if !repeat {
  7106. newArr = append(newArr, arr[i])
  7107. }
  7108. }
  7109. return
  7110. }
  7111. func (c *DialysisAPIController) GetDepartment() {
  7112. adminInfo := c.GetMobileAdminUserInfo()
  7113. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  7114. if err == nil {
  7115. c.ServeSuccessJSON(map[string]interface{}{
  7116. "departments": departments,
  7117. })
  7118. } else {
  7119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7120. return
  7121. }
  7122. }
  7123. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  7124. types, _ := c.GetInt("type", 0)
  7125. start_time := c.GetString("start_time")
  7126. end_time := c.GetString("end_time")
  7127. orgId := c.GetMobileAdminUserInfo().Org.Id
  7128. timeLayout := "2006-01-02"
  7129. loc, _ := time.LoadLocation("Local")
  7130. var startTime int64
  7131. if len(start_time) > 0 {
  7132. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7133. if err != nil {
  7134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7135. return
  7136. }
  7137. startTime = theTime.Unix()
  7138. }
  7139. var endTime int64
  7140. if len(end_time) > 0 {
  7141. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7142. if err != nil {
  7143. utils.ErrorLog(err.Error())
  7144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7145. return
  7146. }
  7147. endTime = theTime.Unix()
  7148. }
  7149. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  7150. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  7151. if err != nil {
  7152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7153. } else {
  7154. c.ServeSuccessJSON(map[string]interface{}{
  7155. "list": list,
  7156. "type": types,
  7157. "stockTotal": stockTotal,
  7158. })
  7159. }
  7160. }
  7161. func (c *DialysisAPIController) GetPrescriptionList() {
  7162. start_time := c.GetString("start_time")
  7163. end_time := c.GetString("end_time")
  7164. schedule_type, _ := c.GetInt64("schedule_type")
  7165. partion_id, _ := c.GetInt64("partion_id")
  7166. orgId := c.GetMobileAdminUserInfo().Org.Id
  7167. timeLayout := "2006-01-02"
  7168. loc, _ := time.LoadLocation("Local")
  7169. var startTime int64
  7170. if len(start_time) > 0 {
  7171. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7172. if err != nil {
  7173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7174. return
  7175. }
  7176. startTime = theTime.Unix()
  7177. }
  7178. var endTime int64
  7179. if len(end_time) > 0 {
  7180. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7181. if err != nil {
  7182. utils.ErrorLog(err.Error())
  7183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7184. return
  7185. }
  7186. endTime = theTime.Unix()
  7187. }
  7188. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  7189. fmt.Println("schedulelist22222222", schedulelist)
  7190. c.ServeSuccessJSON(map[string]interface{}{
  7191. "list": schedulelist,
  7192. })
  7193. return
  7194. }
  7195. func (c *DialysisAPIController) BatchDeleteMonitor() {
  7196. ids := c.GetString("ids")
  7197. //patient_id, _ := c.GetInt64("patient_id")
  7198. //monitoring_date, _ := c.GetInt64("monitoring_date")
  7199. idArray := strings.Split(ids, ",")
  7200. err := service.BatchDeleteMonitor(idArray)
  7201. fmt.Print("err", err)
  7202. //orgid := c.GetMobileAdminUserInfo().Org.Id
  7203. //redis := service.RedisClient()
  7204. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  7205. //redis.Set(key, "", time.Second)
  7206. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  7207. //redis.Set(keyOne, "", time.Second)
  7208. //fmt.Println("keyo呢32332322332332232332",keyOne)
  7209. //redis.Close()
  7210. c.ServeSuccessJSON(map[string]interface{}{
  7211. "msg": "批量删除成功",
  7212. })
  7213. return
  7214. }
  7215. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  7216. id, _ := c.GetInt64("id")
  7217. timeLayout := "2006-01-02"
  7218. loc, _ := time.LoadLocation("Local")
  7219. //start_time := time.Now().Format("2006-01-02")
  7220. start_time := c.GetString("start_time")
  7221. end_time := c.GetString("end_time")
  7222. var startdateunix int64
  7223. if len(start_time) > 0 {
  7224. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7225. if err != nil {
  7226. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7227. return
  7228. }
  7229. startdateunix = theTime.Unix()
  7230. }
  7231. var enddateunix int64
  7232. if len(end_time) > 0 {
  7233. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7234. if err != nil {
  7235. utils.ErrorLog(err.Error())
  7236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7237. return
  7238. }
  7239. enddateunix = theTime.Unix()
  7240. }
  7241. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7242. //nowTime := time.Now()
  7243. //endTime := nowTime.AddDate(-30, 0, 0)
  7244. //endTimes := endTime.Format("2006-01-02")
  7245. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7246. org_id := c.GetMobileAdminUserInfo().Org.Id
  7247. //if org_id == 10579 {
  7248. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7249. // c.ServeSuccessJSON(map[string]interface{}{
  7250. // "list": list,
  7251. // })
  7252. // return
  7253. //} else {
  7254. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7255. // c.ServeSuccessJSON(map[string]interface{}{
  7256. // "list": list,
  7257. // })
  7258. // return
  7259. //}
  7260. if org_id == 9538 || org_id == 10101 || org_id == 10353 || org_id == 9946 {
  7261. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7262. c.ServeSuccessJSON(map[string]interface{}{
  7263. "list": list,
  7264. })
  7265. return
  7266. } else {
  7267. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7268. c.ServeSuccessJSON(map[string]interface{}{
  7269. "list": list,
  7270. })
  7271. }
  7272. return
  7273. }
  7274. func (c *DialysisAPIController) BathDeleteAdviceList() {
  7275. dataBody := make(map[string]interface{}, 0)
  7276. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7277. ids := c.GetString("ids")
  7278. idArray := strings.Split(ids, ",")
  7279. origin, _ := c.GetInt64("origin")
  7280. if origin == 1 {
  7281. err = service.BatchDeleteAdvice(idArray)
  7282. fmt.Print("err", err)
  7283. c.ServeSuccessJSON(map[string]interface{}{
  7284. "msg": "批量删除成功",
  7285. })
  7286. return
  7287. }
  7288. if origin == 2 {
  7289. service.BatchDeleteHisAdvice(idArray)
  7290. }
  7291. }
  7292. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  7293. good_id, _ := c.GetInt64("good_id")
  7294. count, _ := c.GetInt64("count")
  7295. record_time, _ := c.GetInt64("record_time")
  7296. patient_id, _ := c.GetInt64("patient_id")
  7297. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  7298. c.ServeSuccessJSON(map[string]interface{}{
  7299. "detail": detail,
  7300. })
  7301. return
  7302. }
  7303. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  7304. good_id, _ := c.GetInt64("good_id")
  7305. record_time, _ := c.GetInt64("record_time")
  7306. patient_id, _ := c.GetInt64("patient_id")
  7307. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  7308. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  7309. fmt.Print("err", err)
  7310. c.ServeSuccessJSON(map[string]interface{}{
  7311. "msg": "批量删除成功",
  7312. })
  7313. return
  7314. }
  7315. func (c *DialysisAPIController) BatchAdviceCheck() {
  7316. ids := c.GetString("ids")
  7317. idArray := strings.Split(ids, ",")
  7318. creator, _ := c.GetInt64("creator")
  7319. origin, _ := c.GetInt64("origin")
  7320. if origin == 1 {
  7321. err := service.BatchAdviceCheck(idArray, creator)
  7322. fmt.Println(err)
  7323. list, _ := service.GetAdviceExecutionById(idArray)
  7324. c.ServeSuccessJSON(map[string]interface{}{
  7325. "list": list,
  7326. })
  7327. return
  7328. }
  7329. if origin == 2 {
  7330. service.BatchHisAdviceCheck(idArray, creator)
  7331. list, _ := service.GetHisAdviceExecutionById(idArray)
  7332. c.ServeSuccessJSON(map[string]interface{}{
  7333. "list": list,
  7334. })
  7335. return
  7336. }
  7337. }
  7338. func (c *DialysisAPIController) BatchAdviceExecution() {
  7339. ids := c.GetString("ids")
  7340. idArray := strings.Split(ids, ",")
  7341. executionTime := c.GetString("execution_time")
  7342. creator, _ := c.GetInt64("creator")
  7343. timeLayout := "2006-01-02 15:04:05"
  7344. loc, _ := time.LoadLocation("Local")
  7345. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  7346. orgin, _ := c.GetInt64("origin")
  7347. if orgin == 1 {
  7348. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  7349. list, _ := service.GetAdviceExecutionById(idArray)
  7350. fmt.Println(err)
  7351. c.ServeSuccessJSON(map[string]interface{}{
  7352. "list": list,
  7353. })
  7354. return
  7355. }
  7356. if orgin == 2 {
  7357. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  7358. list, _ := service.GetHisAdviceExecutionById(idArray)
  7359. fmt.Println(err)
  7360. c.ServeSuccessJSON(map[string]interface{}{
  7361. "list": list,
  7362. })
  7363. return
  7364. }
  7365. }
  7366. func (c *DialysisAPIController) UpdateStockGoods() {
  7367. good_id, _ := c.GetInt64("good_id")
  7368. record_time, _ := c.GetInt64("record_time")
  7369. patient_id, _ := c.GetInt64("patient_id")
  7370. count, _ := c.GetInt64("count")
  7371. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  7372. fmt.Print("err", err)
  7373. c.ServeSuccessJSON(map[string]interface{}{
  7374. "msg": "更新成功",
  7375. })
  7376. return
  7377. }
  7378. // 当前数据比上一次出库数据少
  7379. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  7380. //查询该患者当天已经出库的耗材信息
  7381. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7382. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7383. for i := len(goods_yc) - 1; i >= 0; i-- {
  7384. goods_yc_temp := goods_yc[i]
  7385. for j := len(goods) - 1; j >= 0; j-- {
  7386. goods_temp := goods[j]
  7387. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7388. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7389. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7390. if goods_yc_temp.Count == goods_temp.Count {
  7391. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7392. goods = append(goods[:j], goods[j+1:]...)
  7393. break
  7394. }
  7395. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7396. if goods_yc_temp.Count > goods_temp.Count {
  7397. temp_count := goods_yc_temp.Count - goods_temp.Count
  7398. goods_yc[i].Count = temp_count
  7399. goods = append(goods[:j], goods[j+1:]...)
  7400. break
  7401. }
  7402. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7403. if goods_yc_temp.Count < goods_temp.Count {
  7404. temp_count := goods_temp.Count - goods_yc_temp.Count
  7405. goods[j].Count = temp_count
  7406. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7407. break
  7408. }
  7409. }
  7410. }
  7411. }
  7412. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7413. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7414. //退库
  7415. if len(goods_yc) > 0 {
  7416. for _, good_yc := range goods_yc {
  7417. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  7418. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  7419. }
  7420. }
  7421. return nil
  7422. }
  7423. // 耗材出库删除
  7424. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7425. // 先根据相关信息查询当天该耗材的出库信息
  7426. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7427. if err != nil {
  7428. return err
  7429. }
  7430. var delete_count int64 = 0
  7431. delete_count = warehouseOutInfos.Count - count
  7432. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7433. // 在出库记录表里记录退库详情
  7434. warehouseOutInfo := &models.WarehouseOutInfo{
  7435. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7436. WarehouseOutId: warehouseOut.ID,
  7437. Status: 1,
  7438. Ctime: time.Now().Unix(),
  7439. OrgId: orgID,
  7440. Type: 1,
  7441. IsSys: 1,
  7442. SysRecordTime: record_time,
  7443. GoodTypeId: good_yc.GoodTypeId,
  7444. GoodId: good_yc.GoodId,
  7445. PatientId: good_yc.PatientId,
  7446. ConsumableType: 2,
  7447. StorehouseId: houseConfig.StorehouseOutInfo,
  7448. IsCheck: 1,
  7449. }
  7450. warehouseOutInfo.Count = count
  7451. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7452. warehouseOutInfo.Price = stockInInfo.Price
  7453. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7454. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7455. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7456. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7457. warehouseOutInfo.Number = warehouseOutInfos.Number
  7458. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7459. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7460. //查找当天是否存在出库记录
  7461. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7462. if errcod == gorm.ErrRecordNotFound {
  7463. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7464. //插入详情明细表
  7465. stockFlow := models.VmStockFlow{
  7466. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7467. WarehouseOutId: warehouseOut.ID,
  7468. GoodId: good_yc.GoodId,
  7469. Number: warehouseOutInfos.Number,
  7470. ProductDate: stockInInfo.ProductDate,
  7471. ExpireDate: stockInInfo.ExpiryDate,
  7472. Count: count,
  7473. Price: stockInInfo.Price,
  7474. Status: 1,
  7475. Ctime: time.Now().Unix(),
  7476. UserOrgId: good_yc.OrgId,
  7477. Manufacturer: stockInInfo.Manufacturer,
  7478. Dealer: stockInInfo.Dealer,
  7479. LicenseNumber: stockInInfo.LicenseNumber,
  7480. IsEdit: 2,
  7481. Creator: creater,
  7482. SystemTime: record_time,
  7483. ConsumableType: 3,
  7484. WarehousingDetailId: 0,
  7485. IsSys: 1,
  7486. UpdateCreator: creater,
  7487. PatientId: patient_id,
  7488. StorehouseId: houseConfig.StorehouseOutInfo,
  7489. }
  7490. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7491. if errflow == gorm.ErrRecordNotFound {
  7492. //创建流水表
  7493. err := service.CreateStockFlowOne(stockFlow)
  7494. fmt.Println("err", err)
  7495. } else if errflow == nil {
  7496. //插入详情明细表
  7497. stockFlow := models.VmStockFlow{
  7498. ID: exsit.ID,
  7499. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7500. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7501. WarehouseOutId: warehouseOut.ID,
  7502. GoodId: good_yc.GoodId,
  7503. Number: warehouseOutInfos.Number,
  7504. ProductDate: stockInInfo.ProductDate,
  7505. ExpireDate: stockInInfo.ExpiryDate,
  7506. Count: exsit.Count - delete_count,
  7507. Price: stockInInfo.Price,
  7508. Status: 1,
  7509. Ctime: time.Now().Unix(),
  7510. UserOrgId: good_yc.OrgId,
  7511. Manufacturer: stockInInfo.Manufacturer,
  7512. Dealer: stockInInfo.Dealer,
  7513. LicenseNumber: stockInInfo.LicenseNumber,
  7514. IsEdit: 2,
  7515. Creator: creater,
  7516. SystemTime: record_time,
  7517. ConsumableType: 3,
  7518. WarehousingDetailId: 0,
  7519. IsSys: 1,
  7520. UpdateCreator: creater,
  7521. PatientId: patient_id,
  7522. StorehouseId: houseConfig.StorehouseOutInfo,
  7523. }
  7524. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7525. }
  7526. if errOne != nil {
  7527. return errOne
  7528. }
  7529. } else if errcod == nil {
  7530. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7531. //插入详情明细表
  7532. stockFlow := models.VmStockFlow{
  7533. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7534. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7535. WarehouseOutId: warehouseOut.ID,
  7536. GoodId: good_yc.GoodId,
  7537. Number: warehouseOutInfos.Number,
  7538. ProductDate: stockInInfo.ProductDate,
  7539. ExpireDate: stockInInfo.ExpiryDate,
  7540. Count: count,
  7541. Price: stockInInfo.Price,
  7542. Status: 1,
  7543. Ctime: time.Now().Unix(),
  7544. UserOrgId: good_yc.OrgId,
  7545. Manufacturer: stockInInfo.Manufacturer,
  7546. Dealer: stockInInfo.Dealer,
  7547. LicenseNumber: stockInInfo.LicenseNumber,
  7548. IsEdit: 2,
  7549. Creator: creater,
  7550. SystemTime: record_time,
  7551. ConsumableType: 3,
  7552. WarehousingDetailId: 0,
  7553. IsSys: 1,
  7554. UpdateCreator: creater,
  7555. PatientId: patient_id,
  7556. ReturnCount: delete_count,
  7557. StorehouseId: houseConfig.StorehouseOutInfo,
  7558. }
  7559. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7560. if errflows == gorm.ErrRecordNotFound {
  7561. //创建流水表
  7562. service.CreateStockFlowOne(stockFlow)
  7563. } else if errflows == nil {
  7564. stockFlow := models.VmStockFlow{
  7565. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7566. ID: exsit.ID,
  7567. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7568. WarehouseOutId: warehouseOut.ID,
  7569. GoodId: good_yc.GoodId,
  7570. Number: warehouseOutInfos.Number,
  7571. ProductDate: stockInInfo.ProductDate,
  7572. ExpireDate: stockInInfo.ExpiryDate,
  7573. Count: exsit.Count - delete_count,
  7574. Price: stockInInfo.Price,
  7575. Status: 1,
  7576. Ctime: time.Now().Unix(),
  7577. UserOrgId: good_yc.OrgId,
  7578. Manufacturer: stockInInfo.Manufacturer,
  7579. Dealer: stockInInfo.Dealer,
  7580. LicenseNumber: stockInInfo.LicenseNumber,
  7581. IsEdit: 2,
  7582. Creator: creater,
  7583. SystemTime: record_time,
  7584. ConsumableType: 3,
  7585. WarehousingDetailId: 0,
  7586. IsSys: 1,
  7587. UpdateCreator: creater,
  7588. PatientId: patient_id,
  7589. ReturnCount: delete_count,
  7590. StorehouseId: houseConfig.StorehouseOutInfo,
  7591. }
  7592. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7593. }
  7594. }
  7595. //更改自动出库的表格
  7596. details := models.BloodAutomaticReduceDetail{
  7597. WarehouseOutId: warehouseOutInfo.ID,
  7598. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7599. PatientId: patient_id,
  7600. Ctime: time.Now().Unix(),
  7601. Mtime: time.Now().Unix(),
  7602. Status: 1,
  7603. RecordTime: record_time,
  7604. OrgId: orgID,
  7605. GoodId: good_yc.GoodId,
  7606. GoodTypeId: good_yc.GoodTypeId,
  7607. Count: count,
  7608. StorehouseId: houseConfig.StorehouseOutInfo,
  7609. }
  7610. //查询当天耗材是否已经存在数据
  7611. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7612. if errcode == gorm.ErrRecordNotFound {
  7613. errTwo := service.CreateAutoReduceRecord(&details)
  7614. if errTwo != nil {
  7615. return errTwo
  7616. }
  7617. } else if errcode == nil {
  7618. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7619. service.CreateAutoReduceRecord(&details)
  7620. }
  7621. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7622. //增加出库库存数量
  7623. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  7624. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  7625. fmt.Println("errOne", errOne)
  7626. // 删除出库完成后,要增加对应批次的库存数量
  7627. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  7628. if errThree != nil {
  7629. return errThree
  7630. }
  7631. if good_yc.Count == 0 {
  7632. return nil
  7633. } else {
  7634. return errors.New("退库和出库数据不匹配")
  7635. }
  7636. }
  7637. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  7638. //查询该患者当天已经出库的耗材信息
  7639. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7640. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7641. for i := len(goods_yc) - 1; i >= 0; i-- {
  7642. goods_yc_temp := goods_yc[i]
  7643. for j := len(goods) - 1; j >= 0; j-- {
  7644. goods_temp := goods[j]
  7645. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7646. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7647. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7648. if goods_yc_temp.Count == goods_temp.Count {
  7649. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7650. goods = append(goods[:j], goods[j+1:]...)
  7651. break
  7652. }
  7653. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7654. if goods_yc_temp.Count > goods_temp.Count {
  7655. temp_count := goods_yc_temp.Count - goods_temp.Count
  7656. goods_yc[i].Count = temp_count
  7657. goods = append(goods[:j], goods[j+1:]...)
  7658. break
  7659. }
  7660. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7661. if goods_yc_temp.Count < goods_temp.Count {
  7662. temp_count := goods_temp.Count - goods_yc_temp.Count
  7663. goods[j].Count = temp_count
  7664. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7665. break
  7666. }
  7667. }
  7668. }
  7669. }
  7670. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7671. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7672. fmt.Println("剩余需要出库的", len(goods))
  7673. if len(goods) > 0 {
  7674. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  7675. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7676. if err == gorm.ErrRecordNotFound {
  7677. //没有记录,则创建出库单
  7678. timeStr := time.Now().Format("2006-01-02")
  7679. timeArr := strings.Split(timeStr, "-")
  7680. total, _ := service.FindAllWarehouseOut(orgID)
  7681. total = total + 1
  7682. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7683. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7684. number = number + total
  7685. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7686. warehouseOut := models.WarehouseOut{
  7687. WarehouseOutOrderNumber: warehousing_out_order,
  7688. OperationTime: time.Now().Unix(),
  7689. OrgId: orgID,
  7690. Creater: creater,
  7691. Ctime: time.Now().Unix(),
  7692. Status: 1,
  7693. WarehouseOutTime: record_time,
  7694. Dealer: 0,
  7695. Manufacturer: 0,
  7696. Type: 1,
  7697. IsSys: 1,
  7698. StorehouseId: houseConfig.StorehouseOutInfo,
  7699. IsCheck: 1,
  7700. }
  7701. err := service.AddSigleWarehouseOut(&warehouseOut)
  7702. if err != nil {
  7703. utils.TraceLog("创建出库单失败 err = %v", err)
  7704. return err
  7705. } else {
  7706. out = warehouseOut
  7707. }
  7708. }
  7709. for _, item := range goods {
  7710. var newCount int64 = 0
  7711. for _, it := range goodOne {
  7712. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  7713. newCount = it.Count
  7714. }
  7715. }
  7716. prepare := models.DialysisBeforePrepare{
  7717. GoodTypeId: item.GoodTypeId,
  7718. GoodId: item.GoodId,
  7719. Count: item.Count,
  7720. StorehouseId: houseConfig.StorehouseOutInfo,
  7721. }
  7722. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  7723. //增加出库数量
  7724. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  7725. }
  7726. }
  7727. if len(goods_yc) > 0 {
  7728. for _, good_yc := range goods_yc {
  7729. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  7730. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  7731. }
  7732. }
  7733. return nil
  7734. }
  7735. // 耗材出库删除
  7736. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  7737. // 先根据相关信息查询当天该耗材的出库信息
  7738. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  7739. if err != nil {
  7740. return err
  7741. }
  7742. var delete_count int64 = 0
  7743. for _, ware := range warehouseOutInfos {
  7744. // 判断当前出库的数据和删除出库数量
  7745. if good_yc.Count <= ware.Count {
  7746. delete_count = good_yc.Count
  7747. } else {
  7748. delete_count = ware.Count
  7749. }
  7750. warehouseOutInfo := &models.WarehouseOutInfo{
  7751. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7752. WarehouseOutId: warehouseOut.ID,
  7753. Status: 1,
  7754. Ctime: time.Now().Unix(),
  7755. Remark: "",
  7756. OrgId: orgID,
  7757. Type: 1,
  7758. Manufacturer: 0,
  7759. Dealer: 0,
  7760. IsSys: 0,
  7761. SysRecordTime: record_time,
  7762. GoodTypeId: good_yc.GoodTypeId,
  7763. GoodId: good_yc.GoodId,
  7764. StorehouseId: warehouseOut.StorehouseId,
  7765. IsCheck: 1,
  7766. }
  7767. warehouseOutInfo.Count = delete_count
  7768. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7769. warehouseOutInfo.Price = stockInInfo.Price
  7770. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7771. if errOne != nil {
  7772. return errOne
  7773. }
  7774. // 删除出库完成后,要改变流水库存(有疑问)
  7775. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  7776. fmt.Println("errOne", errOne)
  7777. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  7778. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7779. //扣减出库数量
  7780. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  7781. if errThree != nil {
  7782. return errThree
  7783. }
  7784. }
  7785. if good_yc.Count == 0 {
  7786. return nil
  7787. } else {
  7788. return errors.New("退库和出库数据不匹配")
  7789. }
  7790. }
  7791. func (this *DialysisAPIController) GetMobileScheduleList() {
  7792. limit, _ := this.GetInt64("limit")
  7793. page, _ := this.GetInt64("page")
  7794. type_options_visible, _ := this.GetInt64("type_options_visible")
  7795. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  7796. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  7797. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  7798. }
  7799. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  7800. newArr = make([]*models.HisPrescriptionProject, 0)
  7801. for i := 0; i < len(arr); i++ {
  7802. repeat := false
  7803. for j := i + 1; j < len(arr); j++ {
  7804. if arr[i].TeamId == arr[j].TeamId && arr[i].PrescriptionId == arr[j].PrescriptionId {
  7805. repeat = true
  7806. break
  7807. }
  7808. }
  7809. if !repeat {
  7810. newArr = append(newArr, arr[i])
  7811. }
  7812. }
  7813. return
  7814. }
  7815. func (this *DialysisAPIController) GetRoleList() {
  7816. admin_user_id, _ := this.GetInt64("admin_user_id")
  7817. orgid := this.GetMobileAdminUserInfo().Org.Id
  7818. list, err := service.GetRoleList(orgid, admin_user_id)
  7819. fmt.Println(err)
  7820. this.ServeSuccessJSON(map[string]interface{}{
  7821. "list": list,
  7822. })
  7823. return
  7824. }
  7825. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7826. // 先根据相关信息查询当天该耗材的出库信息
  7827. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7828. if err != nil {
  7829. return err
  7830. }
  7831. var delete_count int64 = 0
  7832. delete_count = warehouseOutInfos.Count - count
  7833. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7834. // 删除出库完成后,要增加对应批次的库存数量
  7835. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  7836. if errThree != nil {
  7837. return errThree
  7838. }
  7839. //增加退库数量
  7840. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  7841. //扣减出库数量
  7842. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  7843. //查询剩余库存
  7844. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  7845. var sum_count int64
  7846. for _, item := range goodList {
  7847. sum_count += item.StockCount
  7848. }
  7849. // 在出库记录表里记录退库详情
  7850. warehouseOutInfo := &models.WarehouseOutInfo{
  7851. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7852. WarehouseOutId: warehouseOut.ID,
  7853. Status: 1,
  7854. Ctime: time.Now().Unix(),
  7855. OrgId: orgID,
  7856. Type: 1,
  7857. IsSys: 1,
  7858. SysRecordTime: record_time,
  7859. GoodTypeId: good_yc.GoodTypeId,
  7860. GoodId: good_yc.GoodId,
  7861. PatientId: good_yc.PatientId,
  7862. ConsumableType: 2,
  7863. StorehouseId: houseConfig.StorehouseOutInfo,
  7864. IsCheck: 1,
  7865. OverCount: sum_count,
  7866. }
  7867. warehouseOutInfo.Count = count
  7868. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7869. warehouseOutInfo.Price = stockInInfo.Price
  7870. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7871. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7872. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7873. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7874. warehouseOutInfo.Number = warehouseOutInfos.Number
  7875. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7876. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7877. //查找当天是否存在出库记录
  7878. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7879. if errcod == gorm.ErrRecordNotFound {
  7880. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7881. //插入详情明细表
  7882. if errOne != nil {
  7883. return errOne
  7884. }
  7885. //插入详情明细表
  7886. stockFlow := models.VmStockFlow{
  7887. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7888. WarehouseOutId: warehouseOut.ID,
  7889. GoodId: good_yc.GoodId,
  7890. Number: warehouseOutInfos.Number,
  7891. ProductDate: stockInInfo.ProductDate,
  7892. ExpireDate: stockInInfo.ExpiryDate,
  7893. Count: count,
  7894. Price: stockInInfo.Price,
  7895. Status: 1,
  7896. Ctime: record_time,
  7897. UserOrgId: good_yc.OrgId,
  7898. Manufacturer: stockInInfo.Manufacturer,
  7899. Dealer: stockInInfo.Dealer,
  7900. LicenseNumber: stockInInfo.LicenseNumber,
  7901. IsEdit: 2,
  7902. Creator: creater,
  7903. SystemTime: record_time,
  7904. ConsumableType: 3,
  7905. WarehousingDetailId: 0,
  7906. IsSys: 1,
  7907. UpdateCreator: creater,
  7908. PatientId: patient_id,
  7909. StorehouseId: houseConfig.StorehouseOutInfo,
  7910. OverCount: sum_count,
  7911. ProjectId: good_yc.ProjectId,
  7912. }
  7913. err := service.CreateStockFlowOne(stockFlow)
  7914. fmt.Println("err", err)
  7915. } else if errcod == nil {
  7916. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7917. }
  7918. //创建退库单
  7919. operation_time := time.Now().Unix()
  7920. //创建退库单
  7921. timeStr := time.Now().Format("2006-01-02")
  7922. timeArr := strings.Split(timeStr, "-")
  7923. total, _ := service.FindAllCancelStockTotal(orgID)
  7924. total = total + 1
  7925. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7926. cancelStock := models.CancelStock{
  7927. OrderNumber: orderNumber,
  7928. OperaTime: operation_time,
  7929. OrgId: orgID,
  7930. Creater: warehouseOut.Creater,
  7931. Ctime: time.Now().Unix(),
  7932. Status: 1,
  7933. ReturnTime: record_time,
  7934. Type: 1,
  7935. StorehouseId: stockInInfo.StorehouseId,
  7936. IsCheck: 1,
  7937. }
  7938. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  7939. if msgerrkonde == gorm.ErrRecordNotFound {
  7940. service.AddSigleCancelStock(&cancelStock)
  7941. }
  7942. cancel, _ := service.GetLastCancelStockById(orgID)
  7943. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  7944. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  7945. cancelStockInfo := models.CancelStockInfo{
  7946. GoodId: stockInInfo.GoodId,
  7947. CancelStockId: cancel.ID,
  7948. GoodTypeId: stockInInfo.GoodTypeId,
  7949. Count: delete_count,
  7950. Price: stockInInfo.PackingPrice,
  7951. Total: 0,
  7952. ProductDate: stockInInfo.ProductDate,
  7953. ExpiryDate: stockInInfo.ExpiryDate,
  7954. Ctime: record_time,
  7955. Status: 1,
  7956. OrgId: orgID,
  7957. OrderNumber: cancel.OrderNumber,
  7958. Type: 0,
  7959. Dealer: deaerler.DealerName,
  7960. Manufacturer: manufacturer.ManufacturerName,
  7961. Number: stockInInfo.Number,
  7962. RegisterAccount: "",
  7963. Remark: "",
  7964. WarehouseInfoId: stockInInfo.ID,
  7965. PatientId: patient_id,
  7966. RecordDate: record_time,
  7967. StorehouseId: stockInInfo.StorehouseId,
  7968. IsCheck: 1,
  7969. }
  7970. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7971. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  7972. flow := models.VmStockFlow{
  7973. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  7974. GoodId: good_yc.GoodId,
  7975. Number: warehouseOutInfos.Number,
  7976. LicenseNumber: stockInInfo.LicenseNumber,
  7977. Count: delete_count,
  7978. UserOrgId: orgID,
  7979. PatientId: patient_id,
  7980. SystemTime: record_time,
  7981. ConsumableType: 7,
  7982. IsSys: 0,
  7983. WarehousingOrder: "",
  7984. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  7985. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7986. IsEdit: 0,
  7987. CancelStockId: cancel.ID,
  7988. CancelOrderNumber: cancel.OrderNumber,
  7989. Manufacturer: manufacturer.ID,
  7990. Dealer: 0,
  7991. Creator: warehouseOut.Creater,
  7992. UpdateCreator: 0,
  7993. Status: 1,
  7994. Ctime: record_time,
  7995. Mtime: 0,
  7996. Price: stockInInfo.Price,
  7997. WarehousingDetailId: stockInInfo.ID,
  7998. WarehouseOutDetailId: warehouseOutInfos.ID,
  7999. CancelOutDetailId: cancelInfo.ID,
  8000. ProductDate: stockInInfo.ProductDate,
  8001. ExpireDate: stockInInfo.ExpiryDate,
  8002. StorehouseId: houseConfig.StorehouseOutInfo,
  8003. OverCount: sum_count,
  8004. }
  8005. service.CreateStockFlowOne(flow)
  8006. //更改自动出库的表格
  8007. details := models.BloodAutomaticReduceDetail{
  8008. WarehouseOutId: warehouseOutInfo.ID,
  8009. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8010. PatientId: patient_id,
  8011. Ctime: time.Now().Unix(),
  8012. Mtime: time.Now().Unix(),
  8013. Status: 1,
  8014. RecordTime: record_time,
  8015. OrgId: orgID,
  8016. GoodId: good_yc.GoodId,
  8017. GoodTypeId: good_yc.GoodTypeId,
  8018. Count: count,
  8019. StorehouseId: houseConfig.StorehouseOutInfo,
  8020. }
  8021. //查询当天耗材是否已经存在数据
  8022. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8023. if errcode == gorm.ErrRecordNotFound {
  8024. errTwo := service.CreateAutoReduceRecord(&details)
  8025. if errTwo != nil {
  8026. return errTwo
  8027. }
  8028. } else if errcode == nil {
  8029. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8030. service.CreateAutoReduceRecord(&details)
  8031. }
  8032. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8033. //增加出库库存数量
  8034. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  8035. if good_yc.Count == 0 {
  8036. return nil
  8037. } else {
  8038. return errors.New("退库和出库数据不匹配")
  8039. }
  8040. }
  8041. func (this *DialysisAPIController) SavePatientSign() {
  8042. adminUserInfo := this.GetMobileAdminUserInfo()
  8043. patient_id, _ := this.GetInt64("patient_id")
  8044. dialysis_date, _ := this.GetInt64("dialysis_date")
  8045. orgid := adminUserInfo.Org.Id
  8046. var esdata models.DialysisOrder
  8047. var err error
  8048. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  8049. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8050. return
  8051. }
  8052. esdata.Hash = esdata.Hash
  8053. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  8054. order := models.DialysisOrder{
  8055. Hash: esdata.Hash,
  8056. Url: esdata.Url,
  8057. }
  8058. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  8059. redis := service.RedisClient()
  8060. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8061. redis.Set(key, "", time.Second)
  8062. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8063. //清空key 值
  8064. redis.Set(keyOne, "", time.Second)
  8065. //scheduleDateStartOne := startDate.Format("2006-01-02")
  8066. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  8067. //redis.Set(keyTwo, "", time.Second)
  8068. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8069. redis.Set(keyThree, "", time.Second)
  8070. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8071. redis.Set(keyFour, "", time.Second)
  8072. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8073. redis.Set(keyFive, "", time.Second)
  8074. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8075. redis.Set(keySix, "", time.Second)
  8076. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  8077. redis.Set(keySeven, "", time.Second)
  8078. if err != nil {
  8079. fmt.Println(err)
  8080. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8081. return
  8082. }
  8083. this.ServeSuccessJSON(map[string]interface{}{
  8084. "electronic_signature": esdata,
  8085. })
  8086. }
  8087. func (this *DialysisAPIController) GetPatientSign() {
  8088. patient_id, _ := this.GetInt64("patient_id")
  8089. dialysis_date, _ := this.GetInt64("dialysis_date")
  8090. adminUserInfo := this.GetMobileAdminUserInfo()
  8091. orgId := adminUserInfo.Org.Id
  8092. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  8093. if err != nil {
  8094. fmt.Println(err)
  8095. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8096. return
  8097. }
  8098. this.ServeSuccessJSON(map[string]interface{}{
  8099. "dialysisOrder": dialysisOrder,
  8100. })
  8101. }
  8102. func (this *DialysisAPIController) GetScheduleByPatient() {
  8103. patient_id, _ := this.GetInt64("patient_id")
  8104. schedule_date, _ := this.GetInt64("schedule_date")
  8105. orgid := this.GetMobileAdminUserInfo().Org.Id
  8106. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  8107. this.ServeSuccessJSON(map[string]interface{}{
  8108. "schedule": schedule,
  8109. })
  8110. }
  8111. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  8112. org_id := this.GetMobileAdminUserInfo().Org.Id
  8113. patient_id, _ := this.GetInt64("patient_id")
  8114. schedule_date, _ := this.GetInt64("schedule_date")
  8115. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  8116. this.ServeSuccessJSON(map[string]interface{}{
  8117. "order": order,
  8118. })
  8119. }
  8120. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  8121. org_id := this.GetMobileAdminUserInfo().Org.Id
  8122. schedule_date := this.GetString("schedule_date")
  8123. schedule_type, _ := this.GetInt64("schedule_type")
  8124. timeLayout := "2006-01-02"
  8125. loc, _ := time.LoadLocation("Local")
  8126. var startdateunix int64
  8127. if len(schedule_date) > 0 {
  8128. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  8129. if err != nil {
  8130. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8131. return
  8132. }
  8133. startdateunix = theTime.Unix()
  8134. }
  8135. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  8136. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  8137. devices, _ := service.GetAllDevicetByListSix(org_id)
  8138. for key, item := range scheduals {
  8139. // 床位信息
  8140. for _, device := range devices {
  8141. if item.BedId == device.ID {
  8142. scheduals[key].DeviceNumber = device
  8143. break
  8144. }
  8145. }
  8146. }
  8147. this.ServeSuccessJSON(map[string]interface{}{
  8148. "list": list,
  8149. "scheduals": scheduals,
  8150. })
  8151. }
  8152. func (this *DialysisAPIController) SavePatientPicture() {
  8153. patient_id, _ := this.GetInt64("patient_id")
  8154. dialysis_date, _ := this.GetInt64("schedule_date")
  8155. avatar := this.GetString("avatar")
  8156. fmt.Println("patient_id", patient_id)
  8157. orgId := this.GetMobileAdminUserInfo().Org.Id
  8158. order := models.DialysisOrder{
  8159. Url: avatar,
  8160. }
  8161. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  8162. redis := service.RedisClient()
  8163. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8164. redis.Set(key, "", time.Second)
  8165. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8166. //清空key 值
  8167. redis.Set(keyOne, "", time.Second)
  8168. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8169. redis.Set(keyThree, "", time.Second)
  8170. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8171. redis.Set(keyFour, "", time.Second)
  8172. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8173. redis.Set(keyFive, "", time.Second)
  8174. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8175. redis.Set(keySix, "", time.Second)
  8176. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  8177. redis.Set(keySeven, "", time.Second)
  8178. if err != nil {
  8179. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8180. return
  8181. }
  8182. this.ServeSuccessJSON(map[string]interface{}{
  8183. "order": order,
  8184. })
  8185. }
  8186. func (this *DialysisAPIController) ExectionMobileAdvice() {
  8187. ids := this.GetString("ids")
  8188. idSplit := strings.Split(ids, ",")
  8189. orgId := this.GetMobileAdminUserInfo().Org.Id
  8190. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8191. execution_time := this.GetString("exce_time")
  8192. timeLayout2 := "2006-01-02 15:04:05"
  8193. loc, _ := time.LoadLocation("Local")
  8194. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  8195. if errs != nil {
  8196. utils.ErrorLog(errs.Error())
  8197. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8198. return
  8199. }
  8200. //his客户
  8201. if config.IsOpen == 1 {
  8202. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  8203. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  8204. for _, item := range list {
  8205. for _, it := range adviceList {
  8206. if item.DrugId == it.DrugId {
  8207. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8208. }
  8209. }
  8210. }
  8211. for _, item := range list {
  8212. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8213. var sum_out_count int64
  8214. for _, itemThree := range item.ChildDoctorAdvice {
  8215. var prescribing_number int64
  8216. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8217. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8218. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8219. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8220. }
  8221. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8222. prescribing_number = parseIntPrescribingNumber
  8223. }
  8224. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8225. prescribing_number = parseIntPrescribingNumber
  8226. }
  8227. sum_out_count += prescribing_number
  8228. }
  8229. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8230. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8231. //库存不足
  8232. if sum_out_count > drugStockOut.FlushCount {
  8233. this.ServeSuccessJSON(map[string]interface{}{
  8234. "msg": "2",
  8235. "drug": medical,
  8236. "ids": ids,
  8237. })
  8238. return
  8239. }
  8240. }
  8241. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8242. //执行医嘱
  8243. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8244. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  8245. for _, item := range advices {
  8246. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8247. redis := service.RedisClient()
  8248. //清空key 值
  8249. redis.Set(key, "", time.Second)
  8250. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8251. redis.Set(keyTwo, "", time.Second)
  8252. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8253. redis.Set(keyThree, "", time.Second)
  8254. recordDate := theTime.Format("2006-01-02")
  8255. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8256. redis.Set(keyFour, "", time.Second)
  8257. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8258. redis.Set(keyFive, "", time.Second)
  8259. defer redis.Close()
  8260. }
  8261. if errs == nil {
  8262. //药品管理信息
  8263. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8264. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8265. if drugStockConfig.IsOpen == 1 {
  8266. for _, item := range advices {
  8267. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  8268. config, _ := service.GetDrugOpenConfigOne(orgId)
  8269. if config.IsOpen != 1 {
  8270. //查询该药品是否有库存
  8271. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8272. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  8273. if medical.IsUse == 2 {
  8274. if config.IsOpen != 1 {
  8275. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8276. service.HisDrugsDelivery(orgId, creater, &advice)
  8277. if orgId == 3877 || orgId == 10265 {
  8278. //查询该药品是否有出库记录
  8279. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8280. if len(flowMap) == 0 {
  8281. errs := service.UpdateHisAdviceById(advice.ID)
  8282. if errs != nil {
  8283. drugError := models.XtDrugError{
  8284. UserOrgId: orgId,
  8285. DrugId: item.DrugId,
  8286. RecordDate: item.AdviceDate,
  8287. PatientId: item.PatientId,
  8288. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8289. Status: 1,
  8290. Ctime: time.Now().Unix(),
  8291. Mtime: 0,
  8292. SumCount: 0,
  8293. Prescribingnumber: advice.PrescribingNumber,
  8294. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8295. }
  8296. service.CreateDrugError(drugError)
  8297. }
  8298. this.ServeSuccessJSON(map[string]interface{}{
  8299. "msg": "2",
  8300. "drug": medical,
  8301. "ids": ids,
  8302. })
  8303. return
  8304. }
  8305. }
  8306. }
  8307. if pharmacyConfig.IsOpen != 1 {
  8308. service.HisDrugsDelivery(orgId, creater, &advice)
  8309. if orgId == 3877 || orgId == 10265 {
  8310. //查询该药品是否有出库记录
  8311. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8312. if len(flowMap) == 0 {
  8313. errs := service.UpdateHisAdviceById(advice.ID)
  8314. if errs != nil {
  8315. drugError := models.XtDrugError{
  8316. UserOrgId: orgId,
  8317. DrugId: item.DrugId,
  8318. RecordDate: item.AdviceDate,
  8319. PatientId: item.PatientId,
  8320. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8321. Status: 1,
  8322. Ctime: time.Now().Unix(),
  8323. Mtime: 0,
  8324. SumCount: 0,
  8325. Prescribingnumber: advice.PrescribingNumber,
  8326. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8327. }
  8328. service.CreateDrugError(drugError)
  8329. }
  8330. this.ServeSuccessJSON(map[string]interface{}{
  8331. "msg": "2",
  8332. "drug": medical,
  8333. "ids": ids,
  8334. })
  8335. return
  8336. }
  8337. }
  8338. }
  8339. //更新字典里面的库存
  8340. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8341. var sum_count int64
  8342. for _, its := range stockInfo {
  8343. if its.MaxUnit == medical.MaxUnit {
  8344. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8345. }
  8346. sum_count += its.StockMaxNumber + its.StockMinNumber
  8347. }
  8348. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8349. //剩余库存
  8350. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8351. }
  8352. }
  8353. }
  8354. }
  8355. }
  8356. this.ServeSuccessJSON(map[string]interface{}{
  8357. "msg": "1",
  8358. "ids": ids,
  8359. })
  8360. return
  8361. } else {
  8362. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8363. }
  8364. }
  8365. //血透客户
  8366. if config.IsOpen == 2 || config.IsOpen == 0 {
  8367. //药品管理信息
  8368. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8369. if drugStockConfig.IsOpen == 1 {
  8370. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  8371. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  8372. for _, item := range list {
  8373. for _, it := range adviceList {
  8374. if item.DrugId == it.DrugId {
  8375. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8376. }
  8377. }
  8378. }
  8379. for _, item := range list {
  8380. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8381. var sum_out_count int64
  8382. for _, itemThree := range item.ChildDoctorAdvice {
  8383. var prescribing_number int64
  8384. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8385. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8386. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8387. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8388. }
  8389. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8390. prescribing_number = parseIntPrescribingNumber
  8391. }
  8392. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8393. prescribing_number = parseIntPrescribingNumber
  8394. }
  8395. sum_out_count += prescribing_number
  8396. }
  8397. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8398. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8399. //库存不足
  8400. if sum_out_count > drugStockOut.FlushCount {
  8401. this.ServeSuccessJSON(map[string]interface{}{
  8402. "msg": "2",
  8403. "drug": medical,
  8404. "ids": ids,
  8405. })
  8406. return
  8407. }
  8408. }
  8409. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8410. //执行医嘱
  8411. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8412. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8413. for _, item := range advices {
  8414. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8415. redis := service.RedisClient()
  8416. //清空key 值
  8417. redis.Set(key, "", time.Second)
  8418. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8419. redis.Set(keyTwo, "", time.Second)
  8420. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8421. redis.Set(keyThree, "", time.Second)
  8422. recordDate := theTime.Format("2006-01-02")
  8423. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8424. redis.Set(keyFour, "", time.Second)
  8425. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8426. redis.Set(keyFive, "", time.Second)
  8427. defer redis.Close()
  8428. }
  8429. if errs == nil {
  8430. for _, item := range advices {
  8431. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8432. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8433. //查询是否出库按钮开启
  8434. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  8435. if adviceSetting.IsAdviceOpen == 1 {
  8436. //查询是否出库按钮开启
  8437. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  8438. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8439. if prescriptionConfig.IsOpen == 1 {
  8440. if medical.IsUse == 2 {
  8441. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8442. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8443. }
  8444. if pharmacyConfig.IsOpen != 1 {
  8445. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8446. }
  8447. //更新字典里面的库存
  8448. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8449. var sum_count int64
  8450. for _, its := range stockInfo {
  8451. if its.MaxUnit == medical.MaxUnit {
  8452. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8453. }
  8454. sum_count += its.StockMaxNumber + its.StockMinNumber
  8455. }
  8456. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8457. //剩余库存
  8458. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8459. }
  8460. }
  8461. } else {
  8462. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8463. if medical.IsUse == 2 {
  8464. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8465. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8466. }
  8467. if pharmacyConfig.IsOpen != 1 {
  8468. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8469. }
  8470. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8471. var sum_count int64
  8472. for _, its := range stockInfo {
  8473. if its.MaxUnit == medical.MaxUnit {
  8474. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8475. }
  8476. sum_count += its.StockMaxNumber + its.StockMinNumber
  8477. }
  8478. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8479. //剩余库存
  8480. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8481. }
  8482. }
  8483. }
  8484. }
  8485. this.ServeSuccessJSON(map[string]interface{}{
  8486. "msg": "1",
  8487. "ids": ids,
  8488. })
  8489. return
  8490. } else {
  8491. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8492. //执行医嘱
  8493. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8494. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8495. for _, item := range advices {
  8496. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8497. redis := service.RedisClient()
  8498. //清空key 值
  8499. redis.Set(key, "", time.Second)
  8500. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8501. redis.Set(keyTwo, "", time.Second)
  8502. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8503. redis.Set(keyThree, "", time.Second)
  8504. recordDate := theTime.Format("2006-01-02")
  8505. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8506. redis.Set(keyFour, "", time.Second)
  8507. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8508. redis.Set(keyFive, "", time.Second)
  8509. defer redis.Close()
  8510. }
  8511. this.ServeSuccessJSON(map[string]interface{}{
  8512. "msg": "1",
  8513. "ids": ids,
  8514. })
  8515. return
  8516. }
  8517. }
  8518. }
  8519. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  8520. ids := this.GetString("ids")
  8521. idSplit := strings.Split(ids, ",")
  8522. orgId := this.GetMobileAdminUserInfo().Org.Id
  8523. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8524. if config.IsOpen == 1 {
  8525. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  8526. this.ServeSuccessJSON(map[string]interface{}{
  8527. "msg": "1",
  8528. "ids": ids,
  8529. })
  8530. return
  8531. }
  8532. if config.IsOpen == 0 || config.IsOpen == 2 {
  8533. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  8534. this.ServeSuccessJSON(map[string]interface{}{
  8535. "msg": "1",
  8536. "ids": ids,
  8537. })
  8538. return
  8539. }
  8540. }
  8541. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  8542. ids := this.GetString("ids")
  8543. idSplit := strings.Split(ids, ",")
  8544. orgId := this.GetMobileAdminUserInfo().Org.Id
  8545. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8546. //his
  8547. if config.IsOpen == 1 {
  8548. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8549. theTime := time.Now()
  8550. advices := models.HisDoctorAdviceThirty{
  8551. CheckTime: theTime.Unix(),
  8552. Checker: checker,
  8553. UpdatedTime: time.Now().Unix(),
  8554. }
  8555. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  8556. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8557. for _, item := range list {
  8558. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8559. redis := service.RedisClient()
  8560. //清空key 值
  8561. redis.Set(key, "", time.Second)
  8562. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8563. redis.Set(keyTwo, "", time.Second)
  8564. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8565. redis.Set(keyThree, "", time.Second)
  8566. recordDate := theTime.Format("2006-01-02")
  8567. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8568. redis.Set(keyFour, "", time.Second)
  8569. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8570. redis.Set(keyFive, "", time.Second)
  8571. defer redis.Close()
  8572. }
  8573. this.ServeSuccessJSON(map[string]interface{}{
  8574. "msg": "1",
  8575. "ids": ids,
  8576. })
  8577. return
  8578. }
  8579. //血透
  8580. if config.IsOpen == 0 || config.IsOpen == 2 {
  8581. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8582. theTime := time.Now()
  8583. advices := models.DoctorAdvice{
  8584. CheckTime: theTime.Unix(),
  8585. Checker: checker,
  8586. UpdatedTime: time.Now().Unix(),
  8587. }
  8588. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  8589. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8590. for _, item := range list {
  8591. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8592. redis := service.RedisClient()
  8593. //清空key 值
  8594. redis.Set(key, "", time.Second)
  8595. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8596. redis.Set(keyTwo, "", time.Second)
  8597. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8598. redis.Set(keyThree, "", time.Second)
  8599. recordDate := theTime.Format("2006-01-02")
  8600. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8601. redis.Set(keyFour, "", time.Second)
  8602. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8603. redis.Set(keyFive, "", time.Second)
  8604. defer redis.Close()
  8605. }
  8606. this.ServeSuccessJSON(map[string]interface{}{
  8607. "msg": "1",
  8608. "ids": ids,
  8609. })
  8610. return
  8611. }
  8612. }
  8613. func (this *DialysisAPIController) CheckSchedule() {
  8614. patientID, _ := this.GetInt64("patient_id")
  8615. recordDateStr := this.GetString("record_date")
  8616. nurseID, _ := this.GetInt64("start_nurse")
  8617. schedual_type, _ := this.GetInt64("schedual_type")
  8618. bedID, _ := this.GetInt64("bed")
  8619. start_time := this.GetString("start_time")
  8620. fmt.Println("patientID", patientID)
  8621. fmt.Println("recordDateStr", recordDateStr)
  8622. fmt.Println("nurseID", nurseID)
  8623. fmt.Println("schedual_type------", schedual_type)
  8624. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  8625. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8626. return
  8627. }
  8628. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  8629. if parseStartDateErr != nil {
  8630. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  8631. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8632. return
  8633. }
  8634. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8635. if parseErr != nil {
  8636. this.ErrorLog("时间解析失败:%v", parseErr)
  8637. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8638. return
  8639. }
  8640. adminUserInfo := this.GetMobileAdminUserInfo()
  8641. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  8642. if getPatientErr != nil {
  8643. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  8644. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8645. return
  8646. } else if patient == nil {
  8647. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  8648. return
  8649. }
  8650. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  8651. if getNurseErr != nil {
  8652. this.ErrorLog("获取护士失败:%v", getNurseErr)
  8653. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8654. return
  8655. } else if nurse == nil {
  8656. this.ErrorLog("护士不存在")
  8657. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8658. return
  8659. }
  8660. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  8661. if getDeviceNumberErr != nil {
  8662. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  8663. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8664. return
  8665. } else if deviceNumber == nil {
  8666. this.ErrorLog("床位号不存在")
  8667. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8668. return
  8669. }
  8670. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  8671. if getRecordErr != nil {
  8672. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  8673. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8674. return
  8675. } else if dialysisRecord != nil {
  8676. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  8677. return
  8678. }
  8679. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  8680. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  8681. timeLayout := "2006-01-02 15:04:05"
  8682. loc, _ := time.LoadLocation("Local")
  8683. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  8684. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  8685. schedulestartTime := theStartTime.Unix()
  8686. scheduleendTime := theEndTime.Unix()
  8687. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  8688. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  8689. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  8690. //查询该床位是否有人用了
  8691. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  8692. if err == nil {
  8693. if schedule.ID == 0 {
  8694. this.ServeSuccessJSON(map[string]interface{}{
  8695. "status": 0,
  8696. "msg": "请求失败",
  8697. })
  8698. } else {
  8699. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  8700. if order.ID > 0 { //该机位被其他人占用了
  8701. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  8702. return
  8703. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  8704. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  8705. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  8706. this.ServeSuccessJSON(map[string]interface{}{
  8707. "status": 1,
  8708. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  8709. })
  8710. return
  8711. } else {
  8712. this.ServeSuccessJSON(map[string]interface{}{
  8713. "status": 0,
  8714. "msg": "",
  8715. })
  8716. }
  8717. }
  8718. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  8719. this.ServeSuccessJSON(map[string]interface{}{
  8720. "status": 2,
  8721. "msg": "当前机位已有患者在使用,请重新选择!",
  8722. })
  8723. }
  8724. }
  8725. } else {
  8726. this.ServeSuccessJSON(map[string]interface{}{
  8727. "status": 0,
  8728. "msg": "",
  8729. })
  8730. }
  8731. }
  8732. func (this *DialysisAPIController) GetNewDoctorListToday() {
  8733. orgId := this.GetMobileAdminUserInfo().Org.Id
  8734. schedule_type, _ := this.GetInt64("schedule_type")
  8735. partion_type, _ := this.GetInt64("partion_type")
  8736. start_time := this.GetString("start_time")
  8737. timeLayout := "2006-01-02"
  8738. loc, _ := time.LoadLocation("Local")
  8739. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8740. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  8741. _, config := service.FindXTHisRecordByOrgId(orgId)
  8742. appId := this.GetMobileAdminUserInfo().App.Id
  8743. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  8744. if err == nil {
  8745. this.ServeSuccessJSON(map[string]interface{}{
  8746. "list": list,
  8747. "config": config,
  8748. "doctorList": doctorList,
  8749. })
  8750. return
  8751. } else {
  8752. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8753. return
  8754. }
  8755. }
  8756. func (this *DialysisAPIController) SaveMobileInformation() {
  8757. patient_id, _ := this.GetInt64("patient_id")
  8758. record_date, _ := this.GetInt64("record_date")
  8759. startTime := this.GetString("start_time")
  8760. module, _ := this.GetInt64("module")
  8761. remark := this.GetString("remark")
  8762. timeLayout := "2006-01-02 15:04"
  8763. loc, _ := time.LoadLocation("Local")
  8764. if len(startTime) == 0 {
  8765. utils.ErrorLog("len(start_time) == 0")
  8766. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8767. return
  8768. }
  8769. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  8770. if err != nil {
  8771. utils.ErrorLog(err.Error())
  8772. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8773. return
  8774. }
  8775. StartTime := theTime.Unix()
  8776. fmt.Println("startime-------------", StartTime)
  8777. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8778. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  8779. information := models.XtDialysisInformation{
  8780. Module: module,
  8781. PatientId: patient_id,
  8782. RecordDate: record_date,
  8783. ApplicationDate: StartTime,
  8784. Creater: creater,
  8785. ApplicationStatus: 2,
  8786. Checker: 0,
  8787. CheckTime: 0,
  8788. Remark: remark,
  8789. UserOrgId: user_org_id,
  8790. Ctime: time.Now().Unix(),
  8791. Status: 1,
  8792. Mtime: 0,
  8793. }
  8794. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  8795. if infor.ID == 0 {
  8796. service.SaveDialysisInformation(information)
  8797. }
  8798. if infor.ID > 0 {
  8799. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  8800. }
  8801. this.ServeSuccessJSON(map[string]interface{}{
  8802. "information": information,
  8803. })
  8804. return
  8805. }
  8806. func (this *DialysisAPIController) GetMobileInformation() {
  8807. limit, _ := this.GetInt64("limit")
  8808. page, _ := this.GetInt64("page")
  8809. orgid := this.GetMobileAdminUserInfo().Org.Id
  8810. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  8811. appid := this.GetMobileAdminUserInfo().App.Id
  8812. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  8813. patients, _ := service.GetAllpatientThirty(orgid)
  8814. this.ServeSuccessJSON(map[string]interface{}{
  8815. "information": information,
  8816. "total": total,
  8817. "doclist": doclist,
  8818. "patients": patients,
  8819. })
  8820. return
  8821. }
  8822. func (this *DialysisAPIController) GetMobileInformationOne() {
  8823. limit, _ := this.GetInt64("limit")
  8824. page, _ := this.GetInt64("page")
  8825. orgid := this.GetMobileAdminUserInfo().Org.Id
  8826. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  8827. appid := this.GetMobileAdminUserInfo().App.Id
  8828. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  8829. patients, _ := service.GetAllpatientThirty(orgid)
  8830. this.ServeSuccessJSON(map[string]interface{}{
  8831. "information": information,
  8832. "total": total,
  8833. "doclist": doclist,
  8834. "patients": patients,
  8835. })
  8836. return
  8837. }
  8838. func (this *DialysisAPIController) CheckMobileInformation() {
  8839. id, _ := this.GetInt64("id")
  8840. application_status, _ := this.GetInt64("application_status")
  8841. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8842. checktime := time.Now().Unix()
  8843. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  8844. if err == nil {
  8845. this.ServeSuccessJSON(map[string]interface{}{
  8846. "msg": "ok",
  8847. })
  8848. return
  8849. }
  8850. }
  8851. func (c *DialysisAPIController) GetControlMonitorList() {
  8852. partition, _ := c.GetInt64("partition")
  8853. monitorDate := c.GetString("date")
  8854. patient_id, _ := c.GetInt64("patient_id")
  8855. pat_type, _ := c.GetInt64("pat_type")
  8856. timeLayout := "2006-01-02"
  8857. loc, _ := time.LoadLocation("Local")
  8858. var theStartTime int64
  8859. if len(monitorDate) > 0 {
  8860. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  8861. if err != nil {
  8862. theStartTime = 0
  8863. }
  8864. theStartTime = theTime.Unix()
  8865. }
  8866. adminInfo := c.GetMobileAdminUserInfo()
  8867. orgID := adminInfo.Org.Id
  8868. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  8869. if err != nil {
  8870. c.ErrorLog("获取排班信息失败:%v", err)
  8871. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8872. } else {
  8873. if len(monitor) > 0 {
  8874. //获取所有床位
  8875. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  8876. //获取所有分区
  8877. zoneList, _ := service.GetAllZoneByList(orgID)
  8878. //获取透析处方
  8879. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  8880. //获取透前评估
  8881. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  8882. //获取上机
  8883. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  8884. //获取透后
  8885. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  8886. //获取透后监测
  8887. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  8888. //获取所有的患者
  8889. patients, _ := service.GetAllPatientListByListOne(orgID)
  8890. //获取所有透析模式
  8891. treatments, _ := service.GetAllTreatModeByList(orgID)
  8892. //获取所有医嘱
  8893. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  8894. //获取双人核对
  8895. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  8896. //治疗小结
  8897. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  8898. //待消毒
  8899. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  8900. for key, item := range monitor {
  8901. // 获取床位信息
  8902. for _, it := range numberList {
  8903. if item.BedId == it.ID {
  8904. monitor[key].DeviceNumber = it
  8905. break
  8906. }
  8907. }
  8908. //获取分区信息
  8909. for _, it := range zoneList {
  8910. if item.PartitionId == it.ID {
  8911. monitor[key].DeviceZone = it
  8912. }
  8913. }
  8914. for _, prescription := range prescriptions {
  8915. if item.PatientId == prescription.PatientId {
  8916. monitor[key].Prescription = prescription
  8917. break
  8918. }
  8919. }
  8920. for _, it := range checkList {
  8921. if item.PatientId == it.PatientId {
  8922. monitor[key].DoubleCheck = it
  8923. break
  8924. }
  8925. }
  8926. for _, it := range summaryList {
  8927. if item.PatientId == it.PatientId {
  8928. monitor[key].TreatmentSummaryForList = it
  8929. break
  8930. }
  8931. }
  8932. // 透前评估
  8933. for _, assessmentBefore := range assessmentBefores {
  8934. if item.PatientId == assessmentBefore.PatientId {
  8935. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  8936. break
  8937. }
  8938. }
  8939. // 透析上下机
  8940. for _, dialysisOrder := range dialysisOrders {
  8941. if item.PatientId == dialysisOrder.PatientId {
  8942. monitor[key].DialysisOrder = dialysisOrder
  8943. break
  8944. }
  8945. }
  8946. // 治疗小节
  8947. for _, afterDislysis := range AssessmentAfterDislysis {
  8948. if item.PatientId == afterDislysis.PatientId {
  8949. monitor[key].AssessmentAfterDislysis = afterDislysis
  8950. break
  8951. }
  8952. }
  8953. for _, it := range monitorlist {
  8954. if item.PatientId == it.PatientId {
  8955. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  8956. }
  8957. }
  8958. for _, it := range adviceList {
  8959. if item.PatientId == it.PatientId {
  8960. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  8961. }
  8962. }
  8963. for _, patient := range patients {
  8964. if item.PatientId == patient.ID {
  8965. monitor[key].MonitorPatients = patient
  8966. break
  8967. }
  8968. }
  8969. for _, treatment := range treatments {
  8970. if item.ModeId == treatment.ID {
  8971. monitor[key].TreatmentMode = treatment
  8972. break
  8973. }
  8974. }
  8975. for _, infor := range informationList {
  8976. if item.PatientId == infor.PatientId {
  8977. monitor[key].NewDeviceInformation = infor
  8978. break
  8979. }
  8980. }
  8981. }
  8982. }
  8983. }
  8984. patients, err := service.GetAllpatientFourty(orgID)
  8985. var mds []*models.NewMonitorDialysisScheduleList
  8986. if pat_type == 0 {
  8987. for _, item := range monitor {
  8988. mds = append(mds, item)
  8989. }
  8990. }
  8991. //待医嘱核对
  8992. if pat_type == 1 {
  8993. for _, item := range monitor {
  8994. if len(item.AdviceList) > 0 {
  8995. mds = append(mds, item)
  8996. }
  8997. }
  8998. }
  8999. //待开小结
  9000. if pat_type == 2 {
  9001. for _, item := range monitor {
  9002. if item.TreatmentSummaryForList == nil {
  9003. mds = append(mds, item)
  9004. }
  9005. }
  9006. }
  9007. //待下机
  9008. if pat_type == 3 {
  9009. for _, item := range monitor {
  9010. if item.DialysisOrder != nil {
  9011. if item.DialysisOrder.ID > 0 {
  9012. mds = append(mds, item)
  9013. }
  9014. }
  9015. }
  9016. }
  9017. //待消毒
  9018. if pat_type == 4 {
  9019. for _, item := range monitor {
  9020. if item.NewDeviceInformation == nil {
  9021. mds = append(mds, item)
  9022. }
  9023. }
  9024. }
  9025. //待双人核对
  9026. if pat_type == 5 {
  9027. for _, item := range monitor {
  9028. if item.DoubleCheck == nil {
  9029. mds = append(mds, item)
  9030. }
  9031. }
  9032. }
  9033. //医嘱未执行
  9034. if pat_type == 6 {
  9035. for _, item := range monitor {
  9036. if len(item.AdviceList) > 0 {
  9037. mds = append(mds, item)
  9038. }
  9039. }
  9040. }
  9041. //患者未签名
  9042. if pat_type == 7 {
  9043. for _, item := range monitor {
  9044. if item.DialysisOrder != nil {
  9045. if item.DialysisOrder.ID > 0 {
  9046. mds = append(mds, item)
  9047. }
  9048. }
  9049. }
  9050. }
  9051. //目标超滤于实际超滤不同
  9052. if pat_type == 8 {
  9053. for _, item := range monitor {
  9054. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  9055. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  9056. mds = append(mds, item)
  9057. }
  9058. }
  9059. }
  9060. }
  9061. //血压少于5次
  9062. if pat_type == 9 {
  9063. for _, item := range monitor {
  9064. if len(item.MonitoringRecord) < 5 {
  9065. mds = append(mds, item)
  9066. }
  9067. }
  9068. }
  9069. if pat_type == 10 {
  9070. for _, item := range monitor {
  9071. if len(item.MonitoringRecord) == 0 {
  9072. mds = append(mds, item)
  9073. }
  9074. }
  9075. }
  9076. if pat_type == 11 {
  9077. for _, item := range monitor {
  9078. if len(item.MonitoringRecord) > 0 {
  9079. mds = append(mds, item)
  9080. }
  9081. }
  9082. }
  9083. if pat_type == 12 {
  9084. for _, item := range monitor {
  9085. if len(item.MonitoringRecord) > 0 {
  9086. mds = append(mds, item)
  9087. }
  9088. }
  9089. }
  9090. if err == nil {
  9091. c.ServeSuccessJSON(map[string]interface{}{
  9092. "monitor": mds,
  9093. "patients": patients,
  9094. })
  9095. } else {
  9096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9097. }
  9098. }
  9099. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  9100. admin_user_id, _ := c.GetInt64("admin_user_id")
  9101. timeStr := time.Now().Format("2006-01-02")
  9102. timeLayout := "2006-01-02 15:04:05"
  9103. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9104. timenow := timeStringToTime.Unix()
  9105. orgId := c.GetMobileAdminUserInfo().Org.Id
  9106. //查询当前护士的患者
  9107. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  9108. var patientIds []int64
  9109. for _, item := range orderList {
  9110. patientIds = append(patientIds, item.PatientId)
  9111. }
  9112. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  9113. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  9114. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  9115. //药品管理信息
  9116. _, drugStockConfig := service.FindHisConfig(orgId)
  9117. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  9118. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  9119. c.ServeSuccessJSON(map[string]interface{}{
  9120. "adviceList": adviceList,
  9121. "hisAdviceList": hisAdviceList,
  9122. "projectList": projectList,
  9123. "drugStockConfig": drugStockConfig,
  9124. "patientList": patientList,
  9125. "projectConfig": projectConfig,
  9126. })
  9127. }
  9128. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  9129. patient_id, _ := c.GetInt64("patient_id")
  9130. recrods, _ := service.GetLastAcceptRecrods(patient_id)
  9131. c.ServeSuccessJSON(map[string]interface{}{
  9132. "recrods": recrods,
  9133. })
  9134. }
  9135. func (c *DialysisAPIController) ExMobileChangeSch() {
  9136. id_one, _ := c.GetInt64("id_one")
  9137. id_two, _ := c.GetInt64("id_two")
  9138. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9139. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9140. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  9141. //if order2.ID > 0 {
  9142. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9143. // return
  9144. //}
  9145. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9146. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9147. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9148. if count > 0 {
  9149. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9150. return
  9151. }
  9152. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  9153. if count1 > 0 {
  9154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9155. return
  9156. }
  9157. }
  9158. err := service.UpdateScheduleThree(sch, sch_two)
  9159. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9160. if order.ID > 0 {
  9161. //查询该患者的排班机位
  9162. pSchedule, _ := service.GetPscheduleDate(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9163. service.UpdateDialysiOrderByPatientId(id_two, pSchedule.ScheduleType, pSchedule.PartitionId, pSchedule.BedId)
  9164. redis := service.RedisClient()
  9165. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9166. redis.Set(key, "", time.Second)
  9167. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9168. //清空key 值
  9169. redis.Set(keyOne, "", time.Second)
  9170. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderOne)
  9171. //return
  9172. }
  9173. if err == nil {
  9174. //去除当天患者排班中重复数据,保留最后一条数据
  9175. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9176. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9177. c.ServeSuccessJSON(map[string]interface{}{
  9178. "msg": "交换成功",
  9179. })
  9180. } else {
  9181. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9182. return
  9183. }
  9184. }
  9185. func (c *DialysisAPIController) MobileCoverSch() {
  9186. id_one, _ := c.GetInt64("id_one")
  9187. id_two, _ := c.GetInt64("id_two")
  9188. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9189. //针对凤凰医院
  9190. if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
  9191. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9192. if len(advice) > 0 {
  9193. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9194. }
  9195. }
  9196. if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
  9197. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9198. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9199. if len(hisAdvice) > 0 {
  9200. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9201. }
  9202. if len(project) > 0 {
  9203. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9204. }
  9205. }
  9206. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9207. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9208. if order.ID > 0 {
  9209. service.UpdateDialysiOrderByPatientId(id_two, sch_two.ScheduleType, sch_two.PartitionId, sch_two.BedId)
  9210. redis := service.RedisClient()
  9211. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9212. redis.Set(key, "", time.Second)
  9213. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9214. //清空key 值
  9215. redis.Set(keyOne, "", time.Second)
  9216. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9217. //return
  9218. }
  9219. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9220. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9221. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9222. if count > 0 {
  9223. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9224. return
  9225. }
  9226. }
  9227. var new_sch models.Schedule
  9228. new_sch = sch
  9229. new_sch.BedId = sch_two.BedId
  9230. new_sch.ScheduleDate = sch_two.ScheduleDate
  9231. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  9232. new_sch.PartitionId = sch_two.PartitionId
  9233. new_sch.ScheduleType = sch_two.ScheduleType
  9234. new_sch.ID = 0
  9235. //删除原来的排班
  9236. err := service.SaveSchTwo(sch, sch_two)
  9237. //生成新的排班
  9238. if err == nil {
  9239. err2 := service.SaveSch(&new_sch)
  9240. if err2 == nil {
  9241. //去除当天患者排班中重复数据,保留最后一条数据
  9242. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9243. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9244. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  9245. c.ServeSuccessJSON(map[string]interface{}{
  9246. "msg": "覆盖成功",
  9247. "new_sch": new_sch,
  9248. })
  9249. } else {
  9250. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9251. return
  9252. }
  9253. } else {
  9254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9255. return
  9256. }
  9257. }
  9258. //func BatchExectime() {
  9259. //
  9260. //}