dialysis_api_controller.go 383KB

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