dialysis_api_controller.go 355KB

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