dialysis_api_controller.go 304KB

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