dialysis_api_controller.go 307KB

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