@act-registry/esm-act-app 1.0.1-pre.646 → 1.0.1-pre.648

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/3889.js CHANGED
@@ -1 +1 @@
1
- "use strict";(globalThis.webpackChunk_act_registry_esm_act_app=globalThis.webpackChunk_act_registry_esm_act_app||[]).push([["3889"],{174(e,a,t){t.r(a),t.d(a,{default:()=>eQ});var s=t(7858),n=t(4335),r=t(8406),i=t.n(r),o=t(1943),l=t(6204),c=t(6144),d=t(8799),u=t(5275),m=t(6354),h=t(7788),g=t(379),p=t(3368),f=t(1359),b=t(8267),x=t(6932),v=t(8645);let j=["0-9","10-19","20-39","40+","Age unknown"],y=["RHD A","RHD B","RHD C/RHD D","RHD, stage not recorded","RHD, details not recorded"];function C(e,a){return e.filter(e=>e.breakdown===a).map(e=>({label:String(e.label),value:Number(e.patients??0)})).sort((e,a)=>a.value-e.value||e.label.localeCompare(a.label))}let w="Not given",A=(e,a)=>a===w?e("notGiven","Not given"):a,N=(e,a)=>a?Math.round(e/a*100):0;function D(e){let a=e.reduce((e,a)=>e+a,0);if(!a)return e.map(()=>0);let t=e.map(e=>e/a*100),s=t.map(Math.floor),n=100-s.reduce((e,a)=>e+a,0),r=t.map((e,a)=>({index:a,remainder:e-s[a]}));return r.sort((e,a)=>a.remainder-e.remainder||e.index-a.index),r.slice(0,n).forEach(({index:e})=>s[e]+=1),s}let S=["registrants","waitlist","cascade","optimisation"],T=["figure","breakdown","label","procedure","urgency","step","measure","outcome"],R=({figure:e,...a})=>Object.fromEntries(Object.entries(a).filter(([,e])=>e)),k=e=>({registrants:{figure:"registrants",breakdown:["sex","age","disease"].includes(e.breakdown)?"active":"registered"},waitlist:{figure:"waitlist",breakdown:"performed"===e.breakdown||"total"===e.breakdown?e.breakdown:"open"},cascade:{figure:"cascade"},optimisation:{figure:"optimisation",measure:e.measure}})[e.figure],O=(0,n.createContext)(null),M=e=>"cascade"===e.figure?{...e,step:e.step||"Active"}:e,I=["interventionAssigned","interventions"];function P(e,a){return({consultations:e("consultationVisitsLastYear","Consultation visits in the last year"),echocardiogram:e("echoLast13Months","Echocardiogram in the last 13 months"),retainedInCare:e("retainedInCare","Retained in care (seen or given prophylaxis in the last 7 months)"),interventionAssigned:e("patientsWaitingForProcedure","Patients waiting for a procedure"),interventions:e("latestRecommendationsCarriedOut","Latest recommendations carried out"),warfarin:e("inrLast90Days","On warfarin, with an INR in the last 90 days")})[a]??a}function Y(e){let a=(0,h.fU)(),t="ready"===a.status?a.uuids:null;return{counted:"none"===a.status||!!t?.length,countParams:(0,n.useMemo)(()=>t?.length?{...e,clinics:t.join(",")}:e,[e,t]),pending:"pending"===a.status}}var L=t(1327);let F="#009d9a",$="#c6c6c6",H="#007d79",B={Active:F,"Lost to follow-up":"#da1e28","Voluntary inactivity":"#ba4e00","Physical relocation":"#6f6f6f",Deceased:"#161616","Rheumatic Heart Disease/Rheumatic Fever":H,"Acute rheumatic fever":"#08bdba","RHD A":F,"RHD B":H,"RHD C/RHD D":"#005d5d","RHD, details not recorded":"#9ef0f0","Congenital heart disease":"#8a3ffc","Other heart disease":"#d02670",Other:"#d02670",Normal:"#198038","Confirmatory echo normal":"#198038","CHD spontaneous resolution":"#0e6027",Female:"#6929c4",Male:"#1192e8",School:"#002d9c",Community:"#0f62fe","Health facility":"#4589ff","Not recorded":$,"No status recorded":$,"No diagnosis yet":$},_=["#9f1853","#491d8b","#003a6d","#8e6a00","#570408"],E=["#a2191f","#eb6200","#f1c21b"],W=["#520408","#8a3800","#8e6a00"],V=[F,"#d0e2ff"],U=["#8d8d8d","#525252",$],z=(e,a)=>Object.fromEntries(e.map((e,t)=>[e,a[t%a.length]]));function K(){let{t:e}=(0,o.useTranslation)(),a={Active:e("active","Active"),"Lost to follow-up":e("lostToFollowUp","Lost to follow-up"),"Voluntary inactivity":e("voluntaryInactivity","Voluntary inactivity"),"Physical relocation":e("physicalRelocation","Physical relocation"),Deceased:e("deceased","Deceased"),"No status recorded":e("noStatusRecorded","No status recorded"),"No diagnosis yet":e("noDiagnosisYet","No diagnosis yet"),"RHD, details not recorded":e("rhdDetailsNotRecorded","RHD, details not recorded"),"Acute rheumatic fever":e("acuteRheumaticFever","Acute rheumatic fever"),"Congenital heart disease":e("congenitalHeartDisease","Congenital heart disease"),"Other heart disease":e("otherHeartDisease","Other heart disease"),Normal:e("normal","Normal"),Female:e("female","Female"),Male:e("male","Male"),Other:e("other","Other"),"Not recorded":e("notRecorded","Not recorded"),"Age unknown":e("ageUnknown","Age unknown"),School:e("school","School"),Community:e("community","Community"),"Health facility":e("healthFacility","Health facility"),Yes:e("yes","Yes"),No:e("no","No")};return e=>e.name??a[e.label]??e.label}function J(e){let a=(0,n.useRef)(e);return JSON.stringify(a.current)!==JSON.stringify(e)&&(a.current=e),a.current}let G={type:v.FH.NONE};function q({value:e,figure:a}){let t=(0,n.useContext)(O);return a&&t?(0,s.jsx)(l.Link,{href:t.href(a),onClick:e=>{e.button||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||(e.preventDefault(),t.open(a))},children:e}):(0,s.jsx)(s.Fragment,{children:e})}function Q(e){let[a,t]=(0,n.useState)([]),s=a.filter(a=>e.includes(a));return{isShown:e=>!s.length||s.includes(e),toggle:e=>{s.length?1===s.length&&s[0]===e?t([]):t(s.includes(e)?s.filter(a=>a!==e):[...s,e]):t([e])}}}function X({label:e,colour:a,shown:t,onToggle:n,className:r}){return(0,s.jsxs)("button",{type:"button",className:`${L.A.legendToggle} ${t?"":L.A.leftOut} ${r??""}`,"aria-pressed":t,onClick:n,children:[(0,s.jsx)("span",{className:L.A.swatch,style:t?{backgroundColor:a}:void 0,"aria-hidden":"true"}),(0,s.jsx)("span",{children:e})]})}let Z=(e,a)=>({accessibility:{svgAriaLabel:e},height:a,resizable:!0,toolbar:{enabled:!1}});function ee({name:e,counts:a,centre:t,testId:n,withShare:r,figureOf:i}){let l,{t:c}=(0,o.useTranslation)(),d=K(),{isShown:u,toggle:m}=Q(a.map(({label:e})=>e)),h=(l=a.filter(({label:e})=>!B[e]),Object.fromEntries(a.map(e=>[d(e),B[e.label]??_[l.indexOf(e)%_.length]]))),g=a.reduce((e,{value:a})=>e+a,0),p=J(a.filter(({label:e})=>u(e)).map(e=>({group:d(e),value:e.value}))),f=J({...Z(e,"11rem"),color:{scale:h},legend:{enabled:!1},donut:{center:{label:t},alignment:"center"},pie:{labels:{enabled:!1}}});return g?(0,s.jsxs)("div",{className:L.A.donut,children:[(0,s.jsx)("div",{className:L.A.chart,children:(0,s.jsx)(v.V6,{data:p,options:f})}),(0,s.jsx)("ul",{className:L.A.legend,children:a.map(e=>(0,s.jsxs)("li",{className:L.A.legendRow,"data-testid":n,children:[(0,s.jsx)(X,{label:d(e),colour:h[d(e)],shown:u(e.label),onToggle:()=>m(e.label)}),(0,s.jsx)("span",{className:L.A.count,children:(0,s.jsx)(q,{value:e.value,figure:i?.(e.label)})}),r&&(0,s.jsxs)("span",{className:L.A.share,children:[N(e.value,g),"%"]})]},e.label))})]}):(0,s.jsx)("p",{className:L.A.empty,children:c("noPatientsToCount","No patients to count")})}function ea({name:e,steps:a,testId:t,shareOf:n,figureOf:r,height:i="12rem"}){let{t:l}=(0,o.useTranslation)(),{isShown:c,toggle:d}=Q(a.map(({label:e})=>e)),u=J(a.filter(({label:e})=>c(e)).map(({label:e,value:a})=>({group:l(e),value:a}))),m=J({...Z(e,i),color:{scale:z(a.map(({label:e})=>l(e)),[F])},legend:{enabled:!1},axes:{left:{mapsTo:"value"},bottom:{mapsTo:"group",scaleType:v.Wh.LABELS,truncation:G}}});return(0,s.jsxs)("div",{className:L.A.split,children:[(0,s.jsx)("div",{className:L.A.chart,children:(0,s.jsx)(v.kf,{data:u,options:m})}),(0,s.jsx)("ol",{className:L.A.steps,children:((e,a={})=>e.map((t,s)=>{let n=a[t.label]?e.find(e=>e.label===a[t.label]):e[s-1];return{...t,share:n?N(t.value,n.value):null}}))(a,n).map(e=>(0,s.jsxs)("li",{className:L.A.step,"data-testid":t,children:[(0,s.jsx)(X,{label:l(e.label),colour:F,shown:c(e.label),onToggle:()=>d(e.label)}),(0,s.jsx)("span",{className:L.A.count,children:(0,s.jsx)(q,{value:e.value,figure:r?.(e.label)})}),null!==e.share&&(0,s.jsxs)("span",{className:L.A.share,children:[e.share,"%"]})]},e.label))})]})}function et({name:e,segments:a,rows:t,whole:n,testId:r}){let{isShown:i,toggle:o}=Q(a.map(({label:e})=>e)),l=t.map(e=>e.values.reduce((e,a)=>e+a,0)),c=t.map(e=>e.values.reduce((e,t,s)=>e+(i(a[s].label)?t:0),0)),d=Math.max(0,...c);return(0,s.jsxs)("div",{className:L.A.segmented,children:[(0,s.jsx)("ul",{className:L.A.key,"aria-label":e,children:a.map(e=>(0,s.jsx)("li",{children:(0,s.jsx)(X,{label:e.label,colour:e.colour,shown:i(e.label),onToggle:()=>o(e.label)})},e.label))}),(0,s.jsx)("ul",{className:L.A.segmentRows,children:t.map((e,t)=>(0,s.jsxs)("li",{className:L.A.segmentRow,"data-testid":r,children:[(0,s.jsx)("span",{className:L.A.segmentLabel,children:e.label}),(0,s.jsx)("span",{className:L.A.segmentTrack,children:(0,s.jsx)("span",{className:L.A.segmentFill,"data-testid":"dashboard-segment-fill",style:{width:`${N(c[t],n?l[t]:d)}%`},children:e.values.map((e,t)=>e&&i(a[t].label)?(0,s.jsx)("span",{className:L.A.segment,title:`${a[t].label}: ${e}`,"data-testid":"dashboard-segment",style:{flexGrow:e,backgroundColor:a[t].colour},"aria-hidden":"true"},a[t].label):null)})}),(0,s.jsx)("span",{className:L.A.segmentEnd,children:e.end})]},e.key))})]})}let es=["figures","rhdScreening","registrations"],en=(0,n.createContext)(null);function er(e,a,t,s={}){let r=(0,n.useContext)(en),i=JSON.stringify([a,s]);(0,n.useEffect)(()=>{r?.(e,a,t,s)},[r,e,i,t]),(0,n.useEffect)(()=>()=>r?.(e,[],!1,{}),[r,e])}let ei=(e,a,t,s)=>t.map(({label:t,value:n,name:r})=>({section:e,group:a,label:r??t,count:n,period:s}));var eo=t(1740),el=t(1838),ec=t(2379),ed=t(9983),eu=t(7080),em=t(4598),eh=t(8296),eg=t(1488),ep=t(3090),ef=t(1375);function eb({scope:e}){let a,{t}=(0,o.useTranslation)(),{clinicLocationTags:r}=(0,c.useConfig)(),u=(0,h.fU)(),m=(0,g.V)(r.cardiac),p=(0,g.V)(r.primaryCare),f=(0,n.useMemo)(()=>[...m,...p],[m,p]),b="ready"===u.status,x=e.primaryCareClinic||e.cardiacClinic||"",v=b?u.uuids.includes(x)?x:u.uuids[0]??"":x,j=(0,ed.P)(f,v),y="pending"===u.status||b&&!v,C=y?null:{metric:em.ml,clinic:v||null,startDate:i()().subtract(12,"month").format("YYYY-MM-DD"),endDate:i()().format("YYYY-MM-DD"),points:"week"},w=(0,ep.D)(C),A=(0,eh.cO)(w.points),N=A.length>=eh.kK?w.median:null,D=(0,n.useMemo)(()=>(0,eh.Se)(w.points,N),[w.points,N]),S=(0,em.I)(em.ml),T=(0,em.B)(t,em.ml),R=A[A.length-1],k=new URLSearchParams({metric:em.ml});return v&&k.set("clinic",v),a=b&&!v?(0,s.jsx)("p",{className:ef.A.cardNote,children:t("runChartNoClinic","No clinic on your account to chart")}):y||w.isLoading?(0,s.jsx)(l.SkeletonText,{paragraph:!0,lineCount:5}):w.error?(0,s.jsxs)("div",{className:ef.A.history,children:[(0,s.jsx)(l.InlineNotification,{kind:"error",lowContrast:!0,hideCloseButton:!0,statusIconDescription:t("errorIcon","error icon"),title:t("runChartCouldNotLoad","Could not load the run chart"),subtitle:t("restOfDashboardUpToDate","The rest of the Dashboard is up to date.")}),(0,s.jsx)(l.Button,{size:"md",onClick:()=>void w.mutate(),children:t("tryAgain","Try again")})]}):A.length<eh.UB?(0,s.jsx)(ec.X,{points:w.points,period:"week",metric:em.ml,clinic:j}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("p",{className:ef.A.cardMetric,"data-testid":"run-chart-latest",children:(0,eg.C)(t,S,R)}),null!==N&&(0,s.jsx)("p",{className:ef.A.cardNote,children:t("runChartMedianValue","Median {{value}}",{value:N})}),(0,s.jsx)(eu.c,{name:`${T}, ${j}`,points:w.points,median:N,shifts:D,period:"week",kind:S,height:"14rem",compact:!0})]}),(0,s.jsxs)(d.K,{title:t("runCharts","Run charts"),link:{label:t("openRunCharts","Open run charts"),to:`\${openmrsSpaBase}/home/act-run-charts?${k}`},children:[(0,s.jsx)("p",{className:ef.A.cardDescription,children:t("runChartsCardDescription","A clinic's figures over time, worked out from the records as they are now")}),(0,s.jsx)("h3",{className:ef.A.cardHeading,children:t("runChartTitle","{{metric}}, {{clinic}}",{metric:T,clinic:j})}),a]})}var ex=t(9184),ev=t(9610),ej=t(5802),ey=t(4026),eC=t(3361);function ew({figure:e,scope:a,asOf:t,clinicNames:r,onFigure:d,onScope:u,onAsOf:m,onBack:h}){let g,{t:p}=(0,o.useTranslation)(),{dashboard:f,careCascade:x}=(0,c.useConfig)(),v=i()().format("YYYY-MM-DD"),j=(0,n.useMemo)(()=>({endDate:t,...a,...R(e)}),[t,a,e]),{counted:y,countParams:C,pending:w}=Y(j),N=(0,b.y)(y?(g=e.figure,({registrants:f.registrantPatientsReport,waitlist:f.waitlistPatientsReport,cascade:f.cascadePatientsReport,optimisation:f.optimisationPatientsReport})[g]):null,C),{rows:D}=N,{results:S,paginationProps:T}=(0,ey.C)(D,j),O=function(e,a,t){switch(a.figure){case"registrants":return"status"===a.breakdown?{section:e("registrantStatus","Registrant status"),label:a.label}:"registered"===a.breakdown?{section:e("registered","Registered"),label:void 0}:"active"===a.breakdown?{section:e("active","Active"),label:void 0}:{section:e("activeRegistrants","Active registrants"),label:a.label};case"waitlist":return"performed"===a.breakdown?{section:e("performedInTheYear","Performed in the 12 months"),label:a.procedure}:"total"===a.breakdown?{section:e("waitingForAProcedure","Waiting for a procedure"),label:void 0}:{section:e("proceduralWaitlist","Procedural waitlist"),label:[a.procedure,a.urgency].filter(Boolean).map(a=>A(e,a)).join(", ")||void 0};case"cascade":{let s=M(a).step;return{section:e("rhdCareCascade","RHD care cascade"),label:e(t.find(({step:e})=>e===s)?.label??s)}}case"optimisation":return{section:I.includes(a.measure)?e("proceduralWaitlist","Procedural waitlist"):e("medicalOptimisation","Medical optimisation"),label:[P(e,a.measure),"notDone"!==a.outcome?void 0:I.includes(a.measure)?e("stillWaiting","Still waiting"):e("no","No")].filter(Boolean).join(", ")}}}(p,e,x.steps),F="optimisation"===e.figure?"consultations"===e.measure?"consultation":"interventions"===e.measure?"recommendation":"patient":"waitlist"===e.figure&&"total"!==e.breakdown?"recommendation":"patient",$=D.length,H={patient:p("patientsCount","{{count}} patients",{count:$}),consultation:p("consultationsCount","{{count}} consultations",{count:$}),recommendation:p("recommendationsCount","{{count}} recommendations",{count:$})},B=D.some(e=>e.figure_date),_=[p("actId","ACT ID"),p("patient","Patient"),p("age","Age"),p("sex","Sex"),p("cardiacClinic","Cardiac clinic"),p("primaryCareClinic","Primary care clinic"),"optimisation"===e.figure?P(p,e.measure):O.section,...B?[p("date","Date")]:[]],E=e=>[String(e.rhd_id??""),String(e.full_name??""),null===e.age_years||void 0===e.age_years?"":String(e.age_years),String(e.sex??""),String(e.cardiac_clinic??""),String(e.primary_care_clinic??""),String(e.figure_value??""),...B?[e.figure_date?i()(String(e.figure_date)).format("DD/MM/YYYY"):""]:[]],W=(e,a,t)=>(0,s.jsx)(l.Button,{kind:"tertiary",size:"sm",renderIcon:ex.bm,iconDescription:p("remove","Remove"),onClick:t,children:a},e);return(0,s.jsxs)("div",{className:L.A.figure,children:[(0,s.jsxs)("div",{className:L.A.figureBanner,children:[(0,s.jsx)("p",{children:p("openedFromTheDashboard","Opened from the Dashboard: {{figure}}, {{amount}}.",{figure:[O.section,O.label].filter(Boolean).join(", "),amount:H[F],interpolation:{escapeValue:!1}})}),(0,s.jsx)(l.Button,{kind:"ghost",size:"sm",renderIcon:ev.nk,onClick:h,children:p("backToTheDashboard","Back to the Dashboard")})]}),(0,s.jsxs)("div",{className:L.A.figureToolbar,children:[(0,s.jsxs)("div",{className:L.A.chips,children:[JSON.stringify(R(M(e)))!==JSON.stringify(R(M(k(e))))&&W("figure",[O.section,O.label].filter(Boolean).join(": "),()=>d(k(e))),a.cardiacClinic&&W("cardiac",`${p("cardiacClinic","Cardiac clinic")}: ${r.cardiac??""}`,()=>{let{cardiacClinic:e,...t}=a;u(t)}),a.primaryCareClinic&&W("primaryCare",`${p("primaryCareClinic","Primary care clinic")}: ${r.primaryCare??""}`,()=>{let{primaryCareClinic:e,...t}=a;u(t)}),t!==v&&W("asOf",p("asOfDate","As of {{date}}",{date:i()(t).format("DD/MM/YYYY"),interpolation:{escapeValue:!1}}),()=>m(v))]}),!N.error&&!N.isLoading&&!w&&(0,s.jsx)("div",{className:L.A.figureActions,children:(0,s.jsx)(ej.F,{name:`dashboard-${e.figure}`,list:`dashboard:${e.figure}`,identifiers:!0,filters:C,headers:_,rows:()=>D.map(E),disabled:!D.length})})]}),N.error?(0,s.jsx)(l.InlineNotification,{kind:"error",statusIconDescription:p("errorIcon","error icon"),lowContrast:!0,hideCloseButton:!0,title:p("couldNotLoadFigure","Could not load the patients behind this figure")}):N.isLoading||w?(0,s.jsx)(l.SkeletonText,{paragraph:!0,lineCount:6}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:L.A.tableContainer,children:(0,s.jsxs)(l.Table,{size:"sm","aria-label":O.section,children:[(0,s.jsx)(l.TableHead,{children:(0,s.jsx)(l.TableRow,{children:_.slice(1).map(e=>(0,s.jsx)(l.TableHeader,{children:e},e))})}),(0,s.jsx)(l.TableBody,{children:S.map((e,a)=>(0,s.jsx)(l.TableRow,{"data-testid":"dashboard-figure-row",children:E(e).slice(1).map((a,t)=>(0,s.jsx)(l.TableCell,{children:0===t?(0,s.jsx)(eC.e,{row:e}):a},_[t+1]))},`${e.patient_uuid}-${a}`))})]})}),D.length>0&&(0,s.jsx)(l.Pagination,{...T})]})]})}var eA=t(9023);function eN({counts:e,testId:a,figureOf:t,withShares:n,coloured:r}){let{t:i}=(0,o.useTranslation)(),l=K(),{isShown:c,toggle:d}=Q(e.map(e=>e.label));if(!e.length)return(0,s.jsx)("p",{className:L.A.empty,children:i("noPatientsToCount","No patients to count")});let u=Math.max(0,...e.filter(e=>c(e.label)).map(e=>e.value)),m=D(e.map(e=>e.value));return(0,s.jsx)("div",{className:L.A.bars,children:e.map((e,i)=>{let o=r&&B[e.label]||F;return(0,s.jsxs)("div",{className:n?L.A.shareBar:L.A.bar,"data-testid":a,children:[(0,s.jsx)(X,{label:l(e),colour:o,shown:c(e.label),onToggle:()=>d(e.label)}),(0,s.jsx)("span",{className:L.A.track,children:(0,s.jsx)("span",{className:L.A.fill,"data-testid":"dashboard-bar-fill",style:{width:`${c(e.label)?N(e.value,u):0}%`,backgroundColor:o}})}),(0,s.jsx)("span",{className:L.A.count,children:(0,s.jsx)(q,{value:n?e.value.toLocaleString():e.value,figure:t?.(e.label)})}),n&&(0,s.jsxs)("span",{className:L.A.share,children:[m[i],"%"]})]},e.label)})})}function eD({name:e,counts:a,testId:t,figureOf:n}){let{t:r}=(0,o.useTranslation)(),i=K(),{isShown:l,toggle:c}=Q(a.map(e=>e.label));if(!a.length)return(0,s.jsx)("p",{className:L.A.empty,children:r("noPatientsToCount","No patients to count")});let d=Math.max(0,...a.filter(e=>l(e.label)).map(e=>e.value)),u=D(a.map(e=>e.value));return(0,s.jsx)("ol",{className:L.A.columnChart,"aria-label":e,children:a.map((e,a)=>(0,s.jsxs)("li",{className:L.A.column,"data-testid":t,children:[(0,s.jsx)("span",{className:L.A.count,children:(0,s.jsx)(q,{value:e.value,figure:n?.(e.label)})}),(0,s.jsxs)("span",{className:L.A.share,children:[u[a],"%"]}),(0,s.jsx)("span",{className:L.A.columnTrack,"aria-hidden":"true",children:(0,s.jsx)("span",{className:L.A.columnFill,"data-testid":"dashboard-column-fill",style:{height:`${l(e.label)?N(e.value,d):0}%`}})}),(0,s.jsx)(X,{label:i(e),colour:F,shown:l(e.label),onToggle:()=>c(e.label),className:L.A.columnLabel})]},e.label))})}let eS="act.dashboard.collapsed";function eT({name:e,retry:a}){let{t}=(0,o.useTranslation)();return(0,s.jsxs)("div",{className:L.A.state,children:[(0,s.jsx)(l.InlineNotification,{kind:"error",statusIconDescription:t("errorIcon","error icon"),lowContrast:!0,hideCloseButton:!0,title:t("couldNotLoadSection","{{section}} could not load",{section:e}),subtitle:t("restOfDashboardUpToDate","The rest of the Dashboard is up to date.")}),(0,s.jsx)(l.Button,{size:"md",onClick:()=>a(),children:t("tryAgain","Try again")})]})}function eR({title:e,name:a=e,description:t,state:n,clinic:r,onShowAll:i,wide:c,tag:u,controls:m,emptyText:h,embedded:g,collapse:p,exportId:f,children:b}){let{t:x}=(0,o.useTranslation)(),v=(0,s.jsxs)(s.Fragment,{children:[t&&(0,s.jsx)("p",{className:L.A.description,children:t}),m,n.error?(0,s.jsx)(eT,{name:a,retry:n.retry}):n.isLoading?(0,s.jsx)(l.SkeletonText,{paragraph:!0,lineCount:5}):n.isEmpty?(0,s.jsxs)("div",{className:L.A.state,children:[(0,s.jsx)("p",{className:L.A.empty,children:h??(r?x("nobodyAtClinicToCount","Nobody at {{clinic}} to count",{clinic:r}):x("noPatientsToCount","No patients to count"))}),r&&(0,s.jsx)(l.Button,{kind:"tertiary",size:"md",onClick:i,children:x("showAllClinics","Show all clinics")})]}):b]});return g?(0,s.jsx)("div",{className:L.A.embedded,"data-print-title":e,[eo.SS]:f,children:v}):(0,s.jsx)("div",{className:c?L.A.wide:void 0,[eo.SS]:f,children:(0,s.jsx)(d.K,{title:e,tag:u,...p,children:v})})}function ek({label:e,value:a,note:t,isLoading:n,error:r,figure:i}){let{t:c}=(0,o.useTranslation)();return(0,s.jsxs)("div",{className:L.A.figureTile,"data-testid":"dashboard-tile",children:[(0,s.jsx)("span",{className:L.A.figureValue,children:n?(0,s.jsx)(l.SkeletonText,{heading:!0,width:"3rem"}):r||null===a?"–":(0,s.jsx)(q,{value:a,figure:i})}),(0,s.jsxs)("span",{className:L.A.figureText,children:[(0,s.jsx)("span",{className:L.A.figureLabel,children:e}),!n&&(0,s.jsx)("span",{className:L.A.tileNote,children:r?c("couldNotLoad","could not load"):null===a?c("notReported","not reported"):t})]})]})}function eO({container:e,showScreening:a}){let{t}=(0,o.useTranslation)(),n=(0,el.U)(),r=[["keyFigures",t("overview","Overview")],["active",n.active],["waitlist",n.waitlist],["optimisation",n.optimisation],...a?[["screening",t("screening","Screening")]]:[],["runCharts",n.runCharts]];return(0,s.jsxs)(l.Select,{id:"dashboard-jump-to",labelText:t("jumpTo","Jump to"),value:"",onChange:a=>e.current?.querySelector(`[${eo.SS}="${a.target.value}"], [data-jump="${a.target.value}"]`)?.scrollIntoView({behavior:"smooth",block:"start"}),children:[(0,s.jsx)(l.SelectItem,{value:"",text:t("chooseSection","Choose a section"),disabled:!0,hidden:!0}),r.map(([e,a])=>(0,s.jsx)(l.SelectItem,{value:e,text:a},e))]})}function eM(e){let{clinicLocationTags:a}=(0,c.useConfig)(),{sessionLocation:t}=(0,c.useSession)(),s=(0,g.V)(a.cardiac),r=(0,g.V)(a.primaryCare);return(0,n.useMemo)(()=>{let a=(e,a)=>a?e.find(e=>e.uuid===a)?.display??(a===t?.uuid?t.display:a):void 0;return{cardiac:a(s,e.cardiacClinic),primaryCare:a(r,e.primaryCareClinic)}},[s,r,e.cardiacClinic,e.primaryCareClinic,t])}let eI=(e,a)=>({isLoading:e.isLoading,error:e.error,retry:()=>void e.mutate(),isEmpty:a}),eP=e=>e.every(e=>!e.value),eY=(e,a)=>{let t=parseInt(e,10);return Number.isNaN(t)||a.filter(e=>parseInt(e,10)===t).length>1?e:String(t)},eL=["Adherent (80%+)","Adherent"],eF=["Covered today",...eL],e$="1900-01-01",eH=["retainedInCare","echocardiogram","interventionAssigned","interventions","warfarin"],eB="interventions";function e_({measures:e,name:a,testId:t,unit:n="patients"}){let{t:r}=(0,o.useTranslation)(),i="recommendations"===n;return(0,s.jsx)(et,{name:a,segments:[{label:i?r("done","Done"):r("yes","Yes"),colour:V["0"]},{label:i?r("stillWaiting","Still waiting"):r("no","No"),colour:V["1"]}],rows:e.filter(e=>null!==e.notDone).map(e=>{let a={done:e.done,notDone:e.notDone,total:e.done+e.notDone},t={done:(0,s.jsx)(q,{value:e.done,figure:{figure:"optimisation",measure:e.measure,outcome:"done"}}),notDone:(0,s.jsx)(q,{value:e.notDone,figure:{figure:"optimisation",measure:e.measure,outcome:"notDone"}})};return{key:e.measure,label:e.label,values:[e.done,e.notDone],end:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("span",{className:L.A.share,children:[N(e.done,e.done+e.notDone),"%"]}),(0,s.jsx)("span",{className:L.A.doneNotDone,children:i?(0,s.jsx)(o.Trans,{t:r,i18nKey:"doneStillWaitingOfRecommendations",defaults:"<done>{{done}}</done> done, <notDone>{{notDone}}</notDone> still waiting, of {{total}} recommendations",values:a,components:t}):(0,s.jsx)(o.Trans,{t:r,i18nKey:"yesNoOf",defaults:"<done>{{done}}</done> yes, <notDone>{{notDone}}</notDone> no, of {{total}}",values:a,components:t})})]})}}),whole:!0,testId:t})}function eE({scope:e,asOf:a,onShowAll:t}){var r;let m,{t:h}=(0,o.useTranslation)(),{careCascade:g,dashboard:p}=(0,c.useConfig)(),f=(0,n.useMemo)(()=>({endDate:a,...e}),[a,e]),x=eM(e),v=[x.cardiac,x.primaryCare].filter(Boolean).join(", ")||null,{counted:D,countParams:S,pending:T}=Y(f),R=function(){let[e,a]=(0,n.useState)(()=>{try{let e=JSON.parse(window.localStorage.getItem(eS)??"[]");return Array.isArray(e)?e:[]}catch{return[]}}),t=(0,n.useCallback)(e=>{a(a=>{let t=a.includes(e)?a.filter(a=>a!==e):[...a,e];try{window.localStorage.setItem(eS,JSON.stringify(t))}catch{}return t})},[]);return a=>({collapsed:e.includes(a),onToggle:()=>t(a)})}(),k=e=>({...e,isLoading:e.isLoading||T}),O=k((0,b.y)(D?p.registrantsReport:null,S)),M=(0,n.useMemo)(()=>{var e;let a,t;return a=C(e=O.rows,"status"),t=C(e,"age"),{status:a,sex:C(e,"sex"),age:[...t].sort((e,a)=>(j.indexOf(e.label)+1||99)-(j.indexOf(a.label)+1||99)),category:C(e,"disease").sort((e,a)=>(y.indexOf(e.label)+1||99)-(y.indexOf(a.label)+1||99)||e.label.localeCompare(a.label)),registered:a.reduce((e,a)=>e+a.value,0),active:a.find(e=>"Active"===e.label)?.value??0}},[O.rows]),F=k((0,b.y)(D?g.report:null,S)),$=a<i()().format("YYYY-MM-DD"),{cascade:H,leftOutToday:B}=(0,n.useMemo)(()=>{let e=(0,u.o)(F.rows,g.steps),a=$?e.filter(({step:e})=>!eF.includes(e)):e;return{cascade:a,leftOutToday:a.length<e.length}},[F.rows,g.steps,$]),_=(...e)=>H.find(({step:a})=>e.includes(a))?.label,V=_(...eL),K=_("Initiated","Initiated BPG"),J=k((0,b.y)(D?p.waitlistReport:null,S)),G=(0,n.useMemo)(()=>{var e;let a,t,s,n,r,i,o;return e=J.rows,a=e=>String(e??"").trim()||w,t=e.filter(e=>"open"===e.breakdown).map(e=>({procedure:a(e.procedure),urgency:a(e.urgency),recommendations:Number(e.recommendations??0)})),s=e.find(e=>"total"===e.breakdown),n=a=>Number(e.find(e=>"performed"===e.breakdown&&e.procedure===a)?.recommendations??0),r=[...new Set(t.map(e=>String(e.procedure)))].sort(),i=[...new Set(t.map(e=>String(e.urgency)))].sort((e,a)=>e.localeCompare(a,void 0,{numeric:!0})),o=r.map(e=>({procedure:e,counts:i.map(a=>t.filter(t=>t.procedure===e&&t.urgency===a).reduce((e,a)=>e+a.recommendations,0))})),{urgencies:i,rows:o,total:Number(s?.recommendations??0),patients:Number(s?.patients??0),performed:{bmv:n("Mitral balloon valvuloplasty"),surgery:n("Surgery")}}},[J.rows]),Q=(r=G.urgencies,m=e=>E[parseInt(e,10)-1],{...z(r.filter(e=>!m(e)),U),...Object.fromEntries(r.filter(m).map(e=>{let a;return[e,(a=parseInt(e,10),(r.some(t=>t!==e&&parseInt(t,10)===a)&&!/^\d+:/.test(e)?W:E)[a-1])]}))}),X="phone"===(0,c.useLayoutType)(),[Z,es]=(0,n.useState)(X),en=k((0,b.y)(D?p.medicalOptimisationReport:null,S)),el=(0,b.y)(p.showScreening?p.screeningCascadeReport:null,f),ec=(0,b.y)(p.showScreening?p.screeningDiagnosesReport:null,f),ed=en.rows.map(e=>{let a=Number(e.done??0),t=null===e.not_done||void 0===e.not_done?null:Number(e.not_done);return{measure:String(e.measure),label:P(h,String(e.measure)),done:a,notDone:t}}).sort((e,a)=>(eH.indexOf(e.measure)+1||99)-(eH.indexOf(a.measure)+1||99)),eu=ed.filter(e=>e.measure===eB),em=!!J.error&&!en.error&&eu.length>0,eh=ed.filter(e=>!I.includes(e.measure)),eg={"Confirmatory Diagnosis":h("screenedPositive","Screened positive"),Diagnosed:h("diagnosisRecorded","Diagnosis recorded"),"Heart Disease":h("heartDisease","Heart disease")},ep=el.rows.filter(e=>"Active"!==e.step).map(e=>({label:eg[String(e.step)]??String(e.step),value:Number(e.patients??0)})),ef={"Rheumatic Heart Disease/Rheumatic Fever":h("rhd","RHD"),"Congenital heart disease":h("congenital","Congenital"),"Other heart disease":h("other","Other")},ex=(e,a)=>ec.rows.filter(a=>a.breakdown===e).map(e=>({label:String(e[a]??h("none","None")),value:Number(e.patients??0)})),ev=ex("category","category").map(e=>({...e,name:ef[e.label]})),ej=ex("rhdDetails","details"),ey=ej.reduce((e,a)=>e+a.value,0),eC=(...e)=>{let a=F.rows.find(a=>e.includes(String(a.step)));return a?Number(a.patients??0):null},ew=eC("Active"),eA=eC("Prescribed","Prescribed Prophylaxis"),eO={clinic:v,onShowAll:t},e$=F.rows.find(e=>["Prescribed","Prescribed Prophylaxis"].includes(String(e.step))),eW=e=>a=>({figure:"registrants",breakdown:e,label:a}),eV=h("keyFigures","Key figures"),eU=(e,a)=>e.error?[]:a(),ez=h("proceduralWaitlist","Procedural waitlist"),eG=h("activeRegistrants","Active registrants"),eq=h("medicalOptimisationDescription","Of the {{count}} active registrants, except the warfarin row, which counts only those on warfarin",{count:M.active}),eQ=(e,t,[s,n])=>t.flatMap(t=>ei(e,t.label,null===t.notDone?[{label:"",value:t.done}]:[{label:s,value:t.done},{label:n,value:t.notDone}],a));return er("figures",[...eU(O,()=>ei(eV,"",[{label:h("registered","Registered"),value:M.registered},{label:h("active","Active"),value:M.active}],a)),...eU(F,()=>null===eA?[]:ei(eV,"",[{label:h("onSecondaryProphylaxis","On secondary prophylaxis"),value:eA}],a)),...eU(J,()=>ei(eV,"",[{label:h("waitingForAProcedure","Waiting for a procedure"),value:G.patients},{label:h("openRecommendationsFigure","Open recommendations"),value:G.total}],a)),...eU(O,()=>ei(h("registrantStatus","Registrant status"),"",M.status,a)),...eU(F,()=>ei(h("rhdCareCascade","RHD care cascade"),"",H.map(({label:e,value:a})=>({label:h(e),value:a})),a)),...eU(O,()=>[...ei(eG,h("sex","Sex"),M.sex,a),...ei(eG,h("age","Age"),M.age,a),...ei(eG,h("disease","Disease"),M.category,a)]),...eU(J,()=>[...G.rows.flatMap(e=>ei(ez,A(h,e.procedure),e.counts.map((e,a)=>({label:A(h,G.urgencies[a]),value:e})),a))]),...eU(en,()=>eQ(ez,eu,[h("done","Done"),h("stillWaiting","Still waiting")])),...eU(J,()=>[...ei(ez,h("performedLast12Months","Performed in the last 12 months"),[{label:h("mitralBalloonValvuloplasty","Mitral balloon valvuloplasty"),value:G.performed.bmv},{label:h("surgery","Surgery"),value:G.performed.surgery}],a)]),...eU(en,()=>eQ(h("medicalOptimisation","Medical optimisation"),eh,[h("yes","Yes"),h("no","No")])),...!p.showScreening||el.error||ec.error?[]:[...ei(h("screeningCascade","Screening cascade"),h("cascade","Cascade"),ep,a),...ei(h("screeningCascade","Screening cascade"),h("whatTheDiagnosisFound","What the diagnosis found"),ev,a),...ei(h("screeningCascade","Screening cascade"),h("rhdDetails","RHD details"),ej,a)]],[O,F,J,en].some(e=>e.isLoading)||el.isLoading||ec.isLoading),(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:L.A.figures,[eo.SS]:"keyFigures",children:[(0,s.jsx)(ek,{label:h("registered","Registered"),value:M.registered,note:h("everyStatus","every status"),isLoading:O.isLoading,error:O.error,figure:{figure:"registrants",breakdown:"registered"}}),(0,s.jsx)(ek,{label:h("active","Active"),value:M.active,note:h("enrolledAndAlive","enrolled and alive"),isLoading:O.isLoading,error:O.error,figure:{figure:"registrants",breakdown:"active"}}),(0,s.jsx)(ek,{label:h("onSecondaryProphylaxis","On secondary prophylaxis"),value:eA,note:null===ew?h("activeRhdNotReported","active RHD not reported"):h("shareOfActiveRhd","{{share}}% of active RHD",{share:N(eA??0,ew)}),isLoading:F.isLoading,error:F.error,figure:e$&&{figure:"cascade",step:String(e$.step)}}),(0,s.jsx)(ek,{label:h("waitingForAProcedure","Waiting for a procedure"),value:G.patients,note:h("openRecommendations","{{count}} open recommendations",{count:G.total}),isLoading:J.isLoading,error:J.error,figure:{figure:"waitlist",breakdown:"total"}})]}),(0,s.jsxs)("div",{className:L.A.grid,children:[(0,s.jsx)(eR,{title:h("registrantStatus","Registrant status"),description:h("registrantsByStatus","All {{count}} registrants, by where their registration stands",{count:M.registered}),state:eI(O,!M.registered),collapse:R("status"),exportId:"status",...eO,children:(0,s.jsx)(ee,{name:h("registrantStatus","Registrant status"),counts:M.status,centre:h("registrants","registrants"),testId:"dashboard-status",withShare:!0,figureOf:eW("status")})}),(0,s.jsx)(eR,{title:h("rhdCareCascade","RHD care cascade"),description:B?h("careCascadePastDescription","Active RHD patients; each step is a share of the one before. Coverage and adherence are left out, as ACT Core keeps them only for today."):h("careCascadeDescription","Active RHD patients; each step is a share of the one before, Adherent of Initiated"),state:eI(F,eP(H)),collapse:R("cascade"),exportId:"cascade",...eO,children:(0,s.jsx)(ea,{name:h("rhdCareCascade","RHD care cascade"),steps:H,shareOf:V&&K?{[V]:K}:void 0,testId:"dashboard-cascade-step",figureOf:e=>({figure:"cascade",step:H.find(a=>a.label===e)?.step})})}),(0,s.jsx)(eR,{title:h("activeRegistrantsCount","Active registrants: {{count}}",{count:M.active}),name:h("activeRegistrants","Active registrants"),description:h("activeRegistrantsDescription","Sex, age and disease of the patients active today"),state:eI(O,!M.active),wide:!0,collapse:R("active"),exportId:"active",...eO,children:(0,s.jsxs)("div",{className:L.A.columns,children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:L.A.subheading,children:h("sex","Sex")}),(0,s.jsx)(ee,{name:h("sex","Sex"),counts:M.sex,centre:h("activeCentre","active"),testId:"dashboard-sex",withShare:!0,figureOf:eW("sex")})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:L.A.subheading,children:h("age","Age")}),(0,s.jsx)(eD,{name:h("age","Age"),counts:M.age,testId:"dashboard-age",figureOf:eW("age")})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:L.A.subheading,children:h("disease","Disease")}),(0,s.jsx)(eN,{counts:M.category,testId:"dashboard-category",figureOf:eW("disease"),coloured:!0})]})]})}),(0,s.jsxs)(eR,{title:O.error?h("proceduralWaitlistPatients","Procedural waitlist: {{count}} patients",{count:G.patients}):h("proceduralWaitlistOfActive","Procedural waitlist: {{count}} of {{active}} active patients are waiting for a procedure",{count:G.patients,active:M.active}),name:h("proceduralWaitlist","Procedural waitlist"),description:h("waitlistDescription","Open recommendations in each active patient's latest consultation, by urgency"),state:em?eI(en,!1):eI(J,!G.total&&!G.performed.bmv&&!G.performed.surgery&&!en.error&&eu.every(e=>!e.done&&!e.notDone)),wide:!0,collapse:R("waitlist"),exportId:"waitlist",...eO,children:[em?(0,s.jsx)(eT,{name:ez,retry:()=>void J.mutate()}):Z?(0,s.jsxs)("div",{className:L.A.tableContainer,children:[(0,s.jsxs)(l.Table,{size:"sm","aria-label":h("proceduralWaitlist","Procedural waitlist"),children:[(0,s.jsx)(l.TableHead,{children:(0,s.jsxs)(l.TableRow,{children:[(0,s.jsx)(l.TableHeader,{children:h("procedure","Procedure")}),G.urgencies.map(e=>(0,s.jsx)(l.TableHeader,{children:X?eY(e,G.urgencies):A(h,e)},e))]})}),(0,s.jsx)(l.TableBody,{children:G.rows.map(e=>(0,s.jsxs)(l.TableRow,{"data-testid":"dashboard-waitlist-row",children:[(0,s.jsx)(l.TableCell,{children:A(h,e.procedure)}),e.counts.map((a,t)=>(0,s.jsx)(l.TableCell,{children:(0,s.jsx)(q,{value:a,figure:a?{figure:"waitlist",breakdown:"open",procedure:e.procedure,urgency:G.urgencies[t]}:void 0})},G.urgencies[t]))]},e.procedure))})]}),X&&G.urgencies.some(e=>eY(e,G.urgencies)!==e)&&(0,s.jsx)("p",{className:L.A.performed,children:G.urgencies.map(e=>A(h,e)).join(", ")})]}):(0,s.jsx)(et,{name:h("urgency","Urgency"),segments:G.urgencies.map(e=>({label:A(h,e),colour:Q[e]})),rows:G.rows.map(e=>({key:e.procedure,label:A(h,e.procedure),values:e.counts,end:(0,s.jsx)("span",{className:L.A.count,children:(0,s.jsx)(q,{value:e.counts.reduce((e,a)=>e+a,0),figure:{figure:"waitlist",breakdown:"open",procedure:e.procedure}})})})),testId:"dashboard-waitlist-total"}),en.error?(0,s.jsx)("p",{className:L.A.performed,children:h("waitlistFigureCouldNotLoad","{{figure}} could not load",{figure:P(h,eB)})}):eu.length>0&&(0,s.jsx)(s.Fragment,{children:(0,s.jsx)(e_,{measures:eu,name:h("recommendationOutcome","Recommendation outcome"),testId:"dashboard-procedure-measure",unit:"recommendations"})}),!em&&(0,s.jsxs)("div",{className:L.A.sectionFooter,children:[(0,s.jsx)("p",{className:L.A.performed,"data-testid":"dashboard-performed",children:(0,s.jsx)(o.Trans,{t:h,i18nKey:"performedInYear",defaults:"Performed in the 12 months to the date shown: mitral balloon valvuloplasty <bmv>{{bmv}}</bmv>, surgery <surgery>{{surgery}}</surgery>",values:G.performed,components:{bmv:(0,s.jsx)(q,{value:G.performed.bmv,figure:{figure:"waitlist",breakdown:"performed",procedure:"Mitral balloon valvuloplasty"}}),surgery:(0,s.jsx)(q,{value:G.performed.surgery,figure:{figure:"waitlist",breakdown:"performed",procedure:"Surgery"}})}})}),(0,s.jsx)(l.Button,{kind:"ghost",size:"sm",onClick:()=>es(!Z),children:Z?h("showAsAChart","Show as a chart"):h("showAsATable","Show as a table")})]})]}),(0,s.jsxs)(eR,{title:h("medicalOptimisation","Medical optimisation"),description:eq,state:eI(en,eh.every(e=>!e.done&&!e.notDone)),wide:!0,collapse:R("optimisation"),exportId:"optimisation",...eO,children:[(0,s.jsx)(e_,{measures:eh,name:h("outcome","Outcome"),testId:"dashboard-measure"}),eh.filter(e=>null===e.notDone).map(e=>(0,s.jsxs)("p",{className:L.A.sectionFooter,"data-testid":"dashboard-measure-count",children:[(0,s.jsx)("span",{className:L.A.performed,children:e.label}),(0,s.jsx)("span",{className:L.A.count,children:(0,s.jsx)(q,{value:e.done,figure:{figure:"optimisation",measure:e.measure}})})]},e.measure))]}),p.showScreening&&(0,s.jsx)("div",{className:`${L.A.wide} ${L.A.keepTogether}`,"data-jump":"screening","data-export-card":"",children:(0,s.jsx)(d.K,{...R("screening"),title:h("screening","Screening"),tag:(0,s.jsx)(l.Tag,{type:"cool-gray",size:"sm",children:h("screeningProgrammeSites","Screening programme sites")}),children:(0,s.jsxs)(l.Tabs,{children:[(0,s.jsxs)(l.TabList,{"aria-label":h("screening","Screening"),children:[(0,s.jsx)(l.Tab,{children:h("screeningCascade","Screening cascade")}),(0,s.jsx)(l.Tab,{children:h("screeningCounts","Screening counts")}),(0,s.jsx)(l.Tab,{children:h("screeningFromRegistrations","Screening, from registrations")})]}),(0,s.jsxs)(l.TabPanels,{children:[(0,s.jsx)(l.TabPanel,{children:(0,s.jsx)(eR,{title:h("screeningCascade","Screening cascade"),description:h("screeningCascadeDescription","Registrants found by screening (Screen + Yes), and the diagnosis each was given"),state:{isLoading:el.isLoading||ec.isLoading,error:el.error??ec.error,retry:()=>{el.error&&el.mutate(),ec.error&&ec.mutate()},isEmpty:eP(ep)&&eP(ev)},embedded:!0,exportId:"screeningCascade",...eO,children:(0,s.jsxs)("div",{className:L.A.columns,children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:L.A.subheading,children:h("cascade","Cascade")}),(0,s.jsx)(ea,{name:h("screeningCascade","Screening cascade"),steps:ep,testId:"dashboard-screening-step"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:L.A.subheading,children:h("whatTheDiagnosisFound","What the diagnosis found")}),(0,s.jsx)(ee,{name:h("whatTheDiagnosisFound","What the diagnosis found"),counts:ev,centre:h("diagnosed","diagnosed"),testId:"dashboard-screening-category"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:L.A.subheading,children:h("screenDetectedRhd","RHD details of the {{count}}",{count:ey})}),(0,s.jsx)(eN,{counts:ej,testId:"dashboard-screening-details",coloured:!0})]})]})})}),(0,s.jsx)(l.TabPanel,{children:(0,s.jsx)(eJ,{scope:e,...eO})}),(0,s.jsx)(l.TabPanel,{children:(0,s.jsx)(eK,{scope:e,asOf:a,...eO})})]})]})})}),(0,s.jsx)("div",{className:L.A.wide,children:(0,s.jsx)("div",{[eo.SS]:"runCharts",children:(0,s.jsx)(eb,{scope:e})})})]})]})}let eW=["Yes","No","Not recorded"],eV=["Children 0-9","Adolescents 10-19","Adults 20+","Age unknown"],eU=["School","Community","Health facility","Other","Not recorded"],ez=(e,a,t)=>e.filter(e=>e.breakdown===a).map(e=>({label:String(e.label),value:Number(e.patients??0)})).sort((e,a)=>(t.indexOf(e.label)+1||99)-(t.indexOf(a.label)+1||99));function eK({scope:e,asOf:a,clinic:t,onShowAll:r}){let{t:d}=(0,o.useTranslation)(),{dashboard:u}=(0,c.useConfig)(),[m,h]=(0,n.useState)({}),g=m.end??a,p=m.start&&m.start<=g?m.start:i()(g).subtract(364,"day").format("YYYY-MM-DD"),{counted:f,countParams:x,pending:v}=Y((0,n.useMemo)(()=>({startDate:p,endDate:g,...e}),[p,g,e])),j=(0,b.y)(f?u.screeningReport:null,x),{rows:y}=j,C=Number(y.find(e=>"total"===e.breakdown)?.patients??0),w=Number(y.find(e=>"female"===e.breakdown)?.patients??0),A=e=>a=>{let t=a&&i()(a).format("YYYY-MM-DD");t&&t>=e$&&h(a=>({...a,[e]:t}))},D=d("screeningFromRegistrations","Screening, from registrations"),S=d("periodRange","{{start}} to {{end}}",{start:p,end:g});return er("registrations",j.error?[]:[...ei(D,"",[{label:d("registered","Registered"),value:C},{label:d("female","Female"),value:w}],S),...ei(D,d("screenPlus","Screen +"),ez(y,"screen",eW),S),...ei(D,d("ageAtRegistration","Age at registration"),ez(y,"age",eV),S),...ei(D,d("caseDetectedBy","Case detected by"),ez(y,"detected",eU),S)],j.isLoading||v,{registeredFrom:p,registeredTo:g}),(0,s.jsx)(eR,{title:d("screeningFromRegistrations","Screening, from registrations"),description:d("screeningFromRegistrationsDescription","Patients registered in the period: what the registry itself can say about screening"),state:{...eI(j,!C),isLoading:j.isLoading||v},clinic:t,onShowAll:r,embedded:!0,exportId:"registrations",controls:(0,s.jsxs)("div",{className:L.A.registrationControls,children:[(0,s.jsx)(l.InlineNotification,{kind:"info",statusIconDescription:d("infoIcon","info icon"),lowContrast:!0,hideCloseButton:!0,title:d("registrationsNotScreening","Counts registered patients, not people screened: a screen-negative child is never registered.")}),(0,s.jsxs)("div",{className:L.A.filters,children:[(0,s.jsx)(c.OpenmrsDatePicker,{id:"dashboard-registered-from",labelText:d("registeredFrom","Registered from"),value:i()(p).toDate(),minDate:i()(e$).toDate(),maxDate:i()(g).toDate(),onChange:A("start")}),(0,s.jsx)(c.OpenmrsDatePicker,{id:"dashboard-registered-to",labelText:d("registeredTo","Registered to"),value:i()(g).toDate(),minDate:i()(p).toDate(),maxDate:new Date,onChange:A("end")})]})]}),children:(0,s.jsxs)("div",{className:L.A.columns,children:[(0,s.jsxs)("div",{className:L.A.registrationTiles,children:[(0,s.jsxs)("div",{className:L.A.registrationPair,children:[(0,s.jsxs)(l.Tile,{className:L.A.tile,"data-testid":"dashboard-registration-tile",children:[(0,s.jsx)("span",{className:L.A.tileLabel,children:d("registered","Registered")}),(0,s.jsx)("span",{className:L.A.tileValue,children:C})]}),(0,s.jsxs)(l.Tile,{className:L.A.tile,"data-testid":"dashboard-registration-tile",children:[(0,s.jsx)("span",{className:L.A.tileLabel,children:d("female","Female")}),(0,s.jsxs)("span",{className:L.A.tileValue,children:[N(w,C),"%"]})]})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:L.A.subheading,children:d("screenPlus","Screen +")}),(0,s.jsx)(eN,{counts:ez(y,"screen",eW),testId:"dashboard-screen-positive"})]})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:L.A.subheading,children:d("ageAtRegistration","Age at registration")}),(0,s.jsx)(eN,{counts:ez(y,"age",eV),testId:"dashboard-registration-age"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:L.A.subheading,children:d("caseDetectedBy","Case detected by")}),(0,s.jsx)(ee,{name:d("caseDetectedBy","Case detected by"),counts:ez(y,"detected",eU),centre:d("registeredCentre","registered"),testId:"dashboard-detected"})]})]})})}function eJ({scope:e,clinic:a,onShowAll:t}){let{t:r}=(0,o.useTranslation)(),c=(0,n.useMemo)(()=>(0,eA.$9)(eA.t3),[]),{settingLabel:d,metricLabel:u}=(0,eA.NH)(),[m,g]=(0,n.useState)({}),p=m.end??c[1],f=i()(`${p}-01`).subtract(11,"month").format("YYYY-MM"),b=c[c.length-1],x=m.start&&m.start<=p?m.start:f<b?b:f,v=(0,h.fU)(),j="none"===v.status||"ready"===v.status&&v.uuids.length>0,y="pending"===v.status,C=(0,n.useMemo)(()=>j?{clinics:Object.values(e),startMonth:x,endMonth:p}:null,[j,e,x,p]),{summary:w,error:A,isLoading:D,mutate:S}=(0,eA.Y9)(C),T=w?.screened??0,R=new Set(Object.values(e)).size||("ready"===v.status?v.uuids.length:0),k=R*(i()(`${p}-01`).diff(i()(`${x}-01`),"month")+1),O=w?.months??0,M=R>0&&O<k,I=R?M?R>1?r("screeningMonthsEnteredAcross","Counts entered for {{entered}} of {{expected}} months across {{clinics}} clinics. A month not entered adds nothing to these figures.",{entered:O,expected:k,clinics:R}):r("screeningMonthsEnteredOf","Counts entered for {{entered}} of {{expected}} months. A month not entered adds nothing to these figures.",{entered:O,expected:k}):r("screeningMonthsAllEntered","Counts entered for every month in the period"):r("screeningMonthsEnteredEveryClinic","Counts entered for {{count}} months across all clinics",{count:O}),P=(e,a,t,n,r)=>(0,s.jsx)(l.Select,{id:e,labelText:a,value:t,onChange:e=>g(a=>({...a,[n]:e.target.value})),children:r.map(e=>(0,s.jsx)(l.SelectItem,{value:e,text:(0,eA.g6)(e)},e))}),Y=r("clinicsAddedTogether","{{clinics}} added together",{clinics:a}),F=(Object.keys(e).length>1?Y:a)??("ready"===v.status?v.names.join(", ")||r("yourClinics","your clinics"):r("everyClinic","every clinic")),$=r("screeningCounts","Screening counts"),H=r("periodRange","{{start}} to {{end}}",{start:x,end:p});return er("rhdScreening",A||!w?[]:[...ei($,"",[{label:r("monthsEntered","Months entered"),value:O},{label:u.screened,value:T},{label:u.females,value:w.females??0},{label:u.positive,value:w.positive??0}],H),...ei($,r("result","Result"),[{label:r("negative","Negative"),value:w.negative??0},{label:u.positive,value:w.positive??0}],H),...ei($,r("age","Age"),[{label:u.children,value:w.children??0},{label:u.adolescents,value:w.adolescents??0},{label:u.adults,value:w.adults??0}],H),...ei($,r("setting","Setting"),eA.W0.map(e=>({label:d[e],value:w.settings?.[e]??0})),H)],D||y,{screeningFromMonth:x,screeningToMonth:p}),(0,s.jsxs)(eR,{title:r("screeningCounts","Screening counts"),description:r("rhdScreeningDescription","Monthly counts, {{clinic}}, {{start}} to {{end}}",{clinic:F,start:(0,eA.g6)(x),end:(0,eA.g6)(p)}),state:{isLoading:D||y,error:A,retry:()=>void S(),isEmpty:!w?.months},clinic:a,onShowAll:t,embedded:!0,exportId:"rhdScreening",emptyText:a?r("noScreeningCountsAt","No screening counts entered for {{clinic}} in the period",{clinic:a}):r("noScreeningCounts","No screening counts entered in the period"),wide:!0,controls:(0,s.jsxs)("div",{className:L.A.filters,children:[P("dashboard-screening-from",r("fromMonth","From"),x,"start",c.filter(e=>e<=p)),P("dashboard-screening-to",r("toMonth","To"),p,"end",c)]}),children:[M?(0,s.jsx)(l.InlineNotification,{kind:"warning",statusIconDescription:r("warningIcon","warning icon"),lowContrast:!0,hideCloseButton:!0,className:L.A.screeningCoverage,title:I,"data-testid":"dashboard-screening-coverage"}):(0,s.jsx)("p",{className:L.A.screeningCoverage,"data-testid":"dashboard-screening-coverage",children:I}),(0,s.jsxs)("div",{className:L.A.screeningTiles,children:[(0,s.jsxs)(l.Tile,{className:L.A.tile,"data-testid":"dashboard-screening-tile",children:[(0,s.jsx)("span",{className:L.A.tileLabel,children:u.screened}),(0,s.jsx)("span",{className:L.A.tileValue,children:T.toLocaleString()})]}),(0,s.jsxs)(l.Tile,{className:L.A.tile,"data-testid":"dashboard-screening-tile",children:[(0,s.jsx)("span",{className:L.A.tileLabel,children:u.females}),(0,s.jsxs)("span",{className:L.A.tileValue,children:[N(w?.females??0,T),"%"]})]}),(0,s.jsxs)(l.Tile,{className:L.A.tile,"data-testid":"dashboard-screening-tile",children:[(0,s.jsx)("span",{className:L.A.tileLabel,children:u.positive}),(0,s.jsx)("span",{className:L.A.tileValue,children:(w?.positive??0).toLocaleString()})]})]}),(0,s.jsxs)("div",{className:L.A.columns,children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:L.A.subheading,children:r("result","Result")}),(0,s.jsx)(eN,{withShares:!0,counts:[{label:r("negative","Negative"),value:w?.negative??0},{label:u.positive,value:w?.positive??0}],testId:"dashboard-screening-result"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:L.A.subheading,children:r("age","Age")}),(0,s.jsx)(eN,{withShares:!0,counts:[{label:u.children,value:w?.children??0},{label:u.adolescents,value:w?.adolescents??0},{label:u.adults,value:w?.adults??0}],testId:"dashboard-screening-age"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:L.A.subheading,children:r("setting","Setting")}),(0,s.jsx)(eN,{withShares:!0,counts:eA.W0.map(e=>({label:d[e],value:w?.settings?.[e]??0})),testId:"dashboard-screening-setting"})]})]}),(0,s.jsx)("p",{className:L.A.note,children:r("sharesAddUpTo100","Shares are rounded so each group adds up to 100%.")})]})}let eG=["cardiacClinic","primaryCareClinic","asOf",...T],eq=Object.fromEntries(T.map(e=>[e,""]));function eQ(){let{t:e}=(0,o.useTranslation)(),a=(0,f.G)(!1),[t,r,d]=(0,x.y)(eG,"ready"===a.status?a.params:"error"===a.status?{}:"pending"),u=i()().format("YYYY-MM-DD"),g=t.asOf||u,b=e=>r({asOf:e===u?"":e}),v=(0,n.useMemo)(()=>d?void 0:Object.fromEntries(Object.entries({cardiacClinic:t.cardiacClinic,primaryCareClinic:t.primaryCareClinic}).filter(([,e])=>e)),[d,t.cardiacClinic,t.primaryCareClinic]),j=(0,n.useCallback)(e=>r({cardiacClinic:e.cardiacClinic??"",primaryCareClinic:e.primaryCareClinic??""}),[r]),y=(0,n.useMemo)(()=>S.includes(t.figure)?Object.fromEntries(T.map(e=>[e,t[e]])):null,[t]),C="ready"===a.status?Object.keys(a.params):[],w=e=>(0,x.j)(eG,{...t,...e},C),A=e=>{window.history.pushState(window.history.state,"",w(e)),r(e)},N=eM(v??{}),[D,R]=(0,n.useState)({}),k=(0,n.useCallback)((e,a,t,s)=>R(n=>({...n,[e]:{rows:a,isLoading:t,filters:s}})),[]),M=es.flatMap(e=>D[e]?.rows??[]),I=(0,n.useRef)(null),P=(0,c.useSession)(),{dashboard:Y}=(0,c.useConfig)(),F=Y.showScreening,$=(0,h.fU)(),H=[N.cardiac,N.primaryCare].filter(Boolean).join(", ")||("ready"===$.status?$.names.join(", ")||e("yourClinics","your clinics"):e("everyClinic","every clinic"));return(0,s.jsxs)("div",{className:L.A.page,ref:I,children:[(0,s.jsx)("div",{className:L.A.noPrint,children:(0,s.jsx)(m.r,{title:e("dashboard","Dashboard"),illustration:(0,s.jsx)(c.ReportsPictogram,{})})}),(0,s.jsxs)("header",{className:L.A.printHeader,children:[(0,s.jsx)("h1",{children:e("dashboard","Dashboard")}),(0,s.jsxs)("p",{children:[H," \xb7"," ",e("figuresAsOfDate","figures as of {{date}}",{date:(0,c.formatDate)(i()(g).toDate(),{time:!1,noToday:!0})})]}),(0,s.jsxs)("p",{children:[e("printedByOn","Printed by {{user}} on {{date}}",{user:P?.user?.person?.display??P?.user?.display??"",date:(0,c.formatDate)(new Date,{noToday:!0})})," \xb7 ",e("countsOnlyNoPatients","Counts only, no patient data")]})]}),(0,s.jsx)("div",{className:L.A.content,children:"error"===a.status?(0,s.jsx)(l.InlineNotification,{kind:"error",statusIconDescription:e("errorIcon","error icon"),lowContrast:!0,hideCloseButton:!0,title:e("couldNotLoadDashboard","Could not load the dashboard")}):v?y?(0,s.jsx)(ew,{figure:y,scope:v,asOf:g,clinicNames:N,onFigure:e=>r({...eq,...e}),onScope:j,onAsOf:b,onBack:()=>A(eq)}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:`${L.A.filters} ${L.A.toolbar} ${L.A.noPrint}`,children:[(0,s.jsx)(p.QF,{scope:v,onChange:j,idPrefix:"dashboard"}),(0,s.jsx)(c.OpenmrsDatePicker,{id:"dashboard-as-of",labelText:e("figuresAsOf","Figures as of"),value:i()(g).toDate(),minDate:i()(e$).toDate(),maxDate:new Date,onChange:e=>{let a=e&&i()(e).format("YYYY-MM-DD");a&&a>=e$&&b(a)}}),(0,s.jsxs)("div",{className:L.A.download,children:[(0,s.jsx)(eO,{container:I,showScreening:F}),(0,s.jsx)(el.B,{container:I,csvRows:M,csvLoading:es.some(e=>D[e]?.isLoading),filters:{endDate:g,...v},sectionFilters:{rhdScreening:D.rhdScreening?.filters,registrations:D.registrations?.filters},clinics:H,asOf:g,showScreening:F})]})]}),(0,s.jsx)(O.Provider,{value:{href:e=>w({...eq,...e}),open:e=>A({...eq,...e})},children:(0,s.jsx)(en.Provider,{value:k,children:(0,s.jsx)(eE,{scope:v,asOf:g,onShowAll:()=>j({})})})})]}):(0,s.jsx)(l.SkeletonText,{paragraph:!0,lineCount:6})})]})}},3361(e,a,t){t.d(a,{e:()=>i});var s=t(7858);t(4335);var n=t(6144),r=t(9342);function i({row:e,to:a,detail:t,children:o}){let l=String(e.rhd_id??"");return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.ConfigurableLink,{to:a??(0,r.z)(e.patient_uuid),children:String(e.full_name??"")}),o,(0,s.jsx)("span",{className:"-esm-act__patient-cell__actId___l5w3T",children:[l,t].filter(Boolean).join(" \xb7 ")})]})}},9342(e,a,t){t.d(a,{z:()=>s});let s=e=>`\${openmrsSpaBase}/patient/${e}/chart`},9023(e,a,t){t.d(a,{$9:()=>g,NH:()=>f,QI:()=>v,W0:()=>c,Y9:()=>j,fi:()=>m,g6:()=>p,qd:()=>d,t3:()=>h,ws:()=>x});var s=t(8406),n=t.n(s),r=t(1943),i=t(3483),o=t.n(i),l=t(6144);let c=["school","community","facility"],d=["screened","children","adolescents","adults","females","positive"],u=`${l.restBaseUrl}/actcore/screeningcounts`,m=(e,a)=>`${e}_${a}`,h=36,g=e=>Array.from({length:e},(e,a)=>n()().subtract(a,"month").format("YYYY-MM")),p=e=>n()(`${e}-01`).format("MMMM YYYY");function f(){let{t:e}=(0,r.useTranslation)();return{settingLabel:{school:e("school","School"),community:e("community","Community"),facility:e("healthFacility","Health facility")},metricLabel:{screened:e("screened","Screened"),children:e("children0to9","Children 0-9"),adolescents:e("adolescents10to19","Adolescents 10-19"),adults:e("adults20plus","Adults 20+"),females:e("female","Female"),positive:e("positive","Positive")}}}let b=(e,a)=>`${u}?clinic=${encodeURIComponent(e)}&month=${encodeURIComponent(a)}`;function x(e,a){let t=e&&a?b(e,a):null,{data:s,error:n,isLoading:r,mutate:i}=o()(t,async e=>(await (0,l.openmrsFetch)(e)).data,{revalidateOnFocus:!1,revalidateOnReconnect:!1});return{month:s,error:n,isLoading:r,mutate:i}}async function v(e,a,t,s,n){let r=b(e,a),{data:i}=await (0,l.openmrsFetch)(r,{method:"POST",headers:{"Content-Type":"application/json"},body:{counts:t,notes:s}});await n(r,i,{revalidate:!1})}function j(e){let a=e?`${u}/summary?${[...e.clinics.map(e=>`clinic=${encodeURIComponent(e)}`),`startMonth=${e.startMonth}`,`endMonth=${e.endMonth}`].join("&")}`:null,{data:t,error:s,isLoading:n,mutate:r}=o()(a,async e=>(await (0,l.openmrsFetch)(e)).data,{shouldRetryOnError:!1});return{summary:t,error:s,isLoading:n,mutate:r}}},5802(e,a,t){t.d(a,{F:()=>p});var s=t(7858),n=t(4335),r=t(8406),i=t.n(r),o=t(1943),l=t(6204),c=t(771),d=t(6144),u=t(7003),m=t(3571),h=t(1047),g=t(3531);function p({name:e,list:a,identifiers:t,filters:r={},headers:f,rows:b,disabled:x,size:v="sm"}){let{t:j}=(0,o.useTranslation)(),[y,C]=(0,n.useState)(!1),w=async()=>{let s;C(!0);try{s=await b()}catch(e){(0,d.showSnackbar)({kind:"error",title:j("couldNotBuildFile","Could not build the file"),subtitle:(0,h.e)(e)}),C(!1);return}try{await (0,m.kt)({list:a,columns:f,rows:s.length,identifiers:t,filters:r}),(0,g.t)(`${e}-${i()().format("YYYY-MM-DD")}.csv`,f,s)}catch(e){(0,d.showSnackbar)({kind:"error",title:j("couldNotRecordDownload","Could not record the download, so no file was made"),subtitle:(0,h.e)(e)})}finally{C(!1)}};return(0,s.jsx)(d.UserHasAccess,{privilege:u.z$,children:(0,s.jsx)(l.Button,{kind:"tertiary",size:v,renderIcon:c.f5,disabled:x||y,onClick:w,children:y?(0,s.jsx)(l.InlineLoading,{description:j("downloading","Downloading...")}):j("downloadCsv","Download CSV")})})}},4026(e,a,t){t.d(a,{C:()=>o});var s=t(4335),n=t(6144),r=t(4623);let i=[10,25,50,100];function o(e,a){let[t,o]=(0,s.useState)(i[0]),{results:l,currentPage:c,goTo:d}=(0,n.usePagination)(e,t),u=(0,r.T)();return(0,s.useEffect)(()=>d(1),[a,d]),{results:l,paginationProps:{...u,page:c,pageSize:t,pageSizes:i,totalItems:e.length,onChange:({page:e,pageSize:a})=>{o(a),d(e)}}}}},4623(e,a,t){t.d(a,{T:()=>r});var s=t(1943),n=t(6144);function r(){let{t:e}=(0,s.useTranslation)();return{backwardText:e("previousPage","Previous page"),forwardText:e("nextPage","Next page"),itemsPerPageText:e("itemsPerPage","Items per page:"),itemRangeText:(a,t,s)=>e("itemRange","{{min}}–{{max}} of {{count}} items",{min:a,max:t,count:s}),pageRangeText:(e,a)=>(0,n.getCoreTranslation)("paginationOfPages","of {{count}} pages",{count:a})}}}}]);
1
+ "use strict";(globalThis.webpackChunk_act_registry_esm_act_app=globalThis.webpackChunk_act_registry_esm_act_app||[]).push([["3889"],{174(e,a,t){t.r(a),t.d(a,{default:()=>eQ});var s=t(7858),n=t(4335),r=t(8406),i=t.n(r),o=t(1943),l=t(6204),c=t(6144),d=t(8799),u=t(5275),m=t(6354),h=t(7788),g=t(379),p=t(3368),f=t(1359),b=t(8267),x=t(6932),v=t(8645);let j=["0-9","10-19","20-39","40+","Age unknown"],y=["RHD A","RHD B","RHD C/RHD D","RHD, stage not recorded","RHD, details not recorded"];function C(e,a){return e.filter(e=>e.breakdown===a).map(e=>({label:String(e.label),value:Number(e.patients??0)})).sort((e,a)=>a.value-e.value||e.label.localeCompare(a.label))}let w="Not given",N=(e,a)=>a===w?e("notGiven","Not given"):a,A=(e,a)=>a?Math.round(e/a*100):0;function D(e){let a=e.reduce((e,a)=>e+a,0);if(!a)return e.map(()=>0);let t=e.map(e=>e/a*100),s=t.map(Math.floor),n=100-s.reduce((e,a)=>e+a,0),r=t.map((e,a)=>({index:a,remainder:e-s[a]}));return r.sort((e,a)=>a.remainder-e.remainder||e.index-a.index),r.slice(0,n).forEach(({index:e})=>s[e]+=1),s}let S=["registrants","waitlist","cascade","optimisation"],T=["figure","breakdown","label","procedure","urgency","step","measure","outcome"],k=({figure:e,...a})=>Object.fromEntries(Object.entries(a).filter(([,e])=>e)),R=e=>({registrants:{figure:"registrants",breakdown:["sex","age","disease"].includes(e.breakdown)?"active":"registered"},waitlist:{figure:"waitlist",breakdown:"performed"===e.breakdown||"total"===e.breakdown?e.breakdown:"open"},cascade:{figure:"cascade"},optimisation:{figure:"optimisation",measure:e.measure}})[e.figure],O=(0,n.createContext)(null),P=e=>"cascade"===e.figure?{...e,step:e.step||"Active"}:e,M=["interventionAssigned","interventions"];function I(e,a){return({consultations:e("consultationVisitsLastYear","Consultation visits in the last year"),echocardiogram:e("echoLast13Months","Echocardiogram in the last 13 months"),retainedInCare:e("retainedInCare","Retained in care (seen or given prophylaxis in the last 7 months)"),interventionAssigned:e("patientsWaitingForProcedure","Patients waiting for a procedure"),interventions:e("latestRecommendationsCarriedOut","Latest recommendations carried out"),warfarin:e("inrLast90Days","On warfarin, with an INR in the last 90 days")})[a]??a}function Y(e){let a=(0,h.fU)(),t="ready"===a.status?a.uuids:null;return{counted:"none"===a.status||!!t?.length,countParams:(0,n.useMemo)(()=>t?.length?{...e,clinics:t.join(",")}:e,[e,t]),pending:"pending"===a.status}}var L=t(1327);let F="#009d9a",$="#c6c6c6",H="#007d79",B={Active:F,"Lost to follow-up":"#da1e28","Voluntary inactivity":"#ba4e00","Physical relocation":"#6f6f6f",Deceased:"#161616","Rheumatic Heart Disease/Rheumatic Fever":H,"Acute rheumatic fever":"#08bdba","RHD A":F,"RHD B":H,"RHD C/RHD D":"#005d5d","RHD, details not recorded":"#9ef0f0","Congenital heart disease":"#8a3ffc","Other heart disease":"#d02670",Other:"#d02670",Normal:"#198038","Confirmatory echo normal":"#198038","CHD spontaneous resolution":"#0e6027",Female:"#6929c4",Male:"#1192e8",School:"#002d9c",Community:"#0f62fe","Health facility":"#4589ff","Not recorded":$,"Not screen-positive":"#8d8d8d","No status recorded":$,"No diagnosis yet":$},_=["#9f1853","#491d8b","#003a6d","#8e6a00","#570408"],E=["#a2191f","#eb6200","#f1c21b"],W=["#520408","#8a3800","#8e6a00"],V=[F,"#d0e2ff"],U=["#8d8d8d","#525252",$],z=(e,a)=>Object.fromEntries(e.map((e,t)=>[e,a[t%a.length]]));function K(){let{t:e}=(0,o.useTranslation)(),a={Active:e("active","Active"),"Lost to follow-up":e("lostToFollowUp","Lost to follow-up"),"Voluntary inactivity":e("voluntaryInactivity","Voluntary inactivity"),"Physical relocation":e("physicalRelocation","Physical relocation"),Deceased:e("deceased","Deceased"),"No status recorded":e("noStatusRecorded","No status recorded"),"No diagnosis yet":e("noDiagnosisYet","No diagnosis yet"),"RHD, details not recorded":e("rhdDetailsNotRecorded","RHD, details not recorded"),"Acute rheumatic fever":e("acuteRheumaticFever","Acute rheumatic fever"),"Congenital heart disease":e("congenitalHeartDisease","Congenital heart disease"),"Other heart disease":e("otherHeartDisease","Other heart disease"),Normal:e("normal","Normal"),Female:e("female","Female"),Male:e("male","Male"),Other:e("other","Other"),"Not recorded":e("notRecorded","Not recorded"),"Age unknown":e("ageUnknown","Age unknown"),School:e("school","School"),Community:e("community","Community"),"Health facility":e("healthFacility","Health facility"),"Clinical presentation":e("clinicalPresentation","Clinical presentation"),"Pregnancy / labor":e("pregnancyLabor","Pregnancy / labor"),"Coincidental finding":e("coincidentalFinding","Coincidental finding"),"Post-mortem":e("postMortem","Post-mortem"),"Not screen-positive":e("notScreenPositive","Not screen-positive"),Yes:e("yes","Yes"),No:e("no","No")};return e=>e.name??a[e.label]??e.label}function J(e){let a=(0,n.useRef)(e);return JSON.stringify(a.current)!==JSON.stringify(e)&&(a.current=e),a.current}let G={type:v.FH.NONE};function q({value:e,figure:a}){let t=(0,n.useContext)(O);return a&&t?(0,s.jsx)(l.Link,{href:t.href(a),onClick:e=>{e.button||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||(e.preventDefault(),t.open(a))},children:e}):(0,s.jsx)(s.Fragment,{children:e})}function Q(e){let[a,t]=(0,n.useState)([]),s=a.filter(a=>e.includes(a));return{isShown:e=>!s.length||s.includes(e),toggle:e=>{s.length?1===s.length&&s[0]===e?t([]):t(s.includes(e)?s.filter(a=>a!==e):[...s,e]):t([e])}}}function X({label:e,colour:a,shown:t,onToggle:n,className:r}){return(0,s.jsxs)("button",{type:"button",className:`${L.A.legendToggle} ${t?"":L.A.leftOut} ${r??""}`,"aria-pressed":t,onClick:n,children:[(0,s.jsx)("span",{className:L.A.swatch,style:t?{backgroundColor:a}:void 0,"aria-hidden":"true"}),(0,s.jsx)("span",{children:e})]})}let Z=(e,a)=>({accessibility:{svgAriaLabel:e},height:a,resizable:!0,toolbar:{enabled:!1}});function ee({name:e,counts:a,centre:t,testId:n,withShare:r,figureOf:i}){let l,{t:c}=(0,o.useTranslation)(),d=K(),{isShown:u,toggle:m}=Q(a.map(({label:e})=>e)),h=(l=a.filter(({label:e})=>!B[e]),Object.fromEntries(a.map(e=>[d(e),B[e.label]??_[l.indexOf(e)%_.length]]))),g=a.reduce((e,{value:a})=>e+a,0),p=J(a.filter(({label:e})=>u(e)).map(e=>({group:d(e),value:e.value}))),f=J({...Z(e,"11rem"),color:{scale:h},legend:{enabled:!1},donut:{center:{label:t},alignment:"center"},pie:{labels:{enabled:!1}}});return g?(0,s.jsxs)("div",{className:L.A.donut,children:[(0,s.jsx)("div",{className:L.A.chart,children:(0,s.jsx)(v.V6,{data:p,options:f})}),(0,s.jsx)("ul",{className:L.A.legend,children:a.map(e=>(0,s.jsxs)("li",{className:L.A.legendRow,"data-testid":n,children:[(0,s.jsx)(X,{label:d(e),colour:h[d(e)],shown:u(e.label),onToggle:()=>m(e.label)}),(0,s.jsx)("span",{className:L.A.count,children:(0,s.jsx)(q,{value:e.value,figure:i?.(e.label)})}),r&&(0,s.jsxs)("span",{className:L.A.share,children:[A(e.value,g),"%"]})]},e.label))})]}):(0,s.jsx)("p",{className:L.A.empty,children:c("noPatientsToCount","No patients to count")})}function ea({name:e,steps:a,testId:t,shareOf:n,figureOf:r,height:i="12rem"}){let{t:l}=(0,o.useTranslation)(),{isShown:c,toggle:d}=Q(a.map(({label:e})=>e)),u=J(a.filter(({label:e})=>c(e)).map(({label:e,value:a})=>({group:l(e),value:a}))),m=J({...Z(e,i),color:{scale:z(a.map(({label:e})=>l(e)),[F])},legend:{enabled:!1},axes:{left:{mapsTo:"value"},bottom:{mapsTo:"group",scaleType:v.Wh.LABELS,truncation:G}}});return(0,s.jsxs)("div",{className:L.A.split,children:[(0,s.jsx)("div",{className:L.A.chart,children:(0,s.jsx)(v.kf,{data:u,options:m})}),(0,s.jsx)("ol",{className:L.A.steps,children:((e,a={})=>e.map((t,s)=>{let n=a[t.label]?e.find(e=>e.label===a[t.label]):e[s-1];return{...t,share:n?A(t.value,n.value):null}}))(a,n).map(e=>(0,s.jsxs)("li",{className:L.A.step,"data-testid":t,children:[(0,s.jsx)(X,{label:l(e.label),colour:F,shown:c(e.label),onToggle:()=>d(e.label)}),(0,s.jsx)("span",{className:L.A.count,children:(0,s.jsx)(q,{value:e.value,figure:r?.(e.label)})}),null!==e.share&&(0,s.jsxs)("span",{className:L.A.share,children:[e.share,"%"]})]},e.label))})]})}function et({name:e,segments:a,rows:t,whole:n,testId:r}){let{isShown:i,toggle:o}=Q(a.map(({label:e})=>e)),l=t.map(e=>e.values.reduce((e,a)=>e+a,0)),c=t.map(e=>e.values.reduce((e,t,s)=>e+(i(a[s].label)?t:0),0)),d=Math.max(0,...c);return(0,s.jsxs)("div",{className:L.A.segmented,children:[(0,s.jsx)("ul",{className:L.A.key,"aria-label":e,children:a.map(e=>(0,s.jsx)("li",{children:(0,s.jsx)(X,{label:e.label,colour:e.colour,shown:i(e.label),onToggle:()=>o(e.label)})},e.label))}),(0,s.jsx)("ul",{className:L.A.segmentRows,children:t.map((e,t)=>(0,s.jsxs)("li",{className:L.A.segmentRow,"data-testid":r,children:[(0,s.jsx)("span",{className:L.A.segmentLabel,children:e.label}),(0,s.jsx)("span",{className:L.A.segmentTrack,children:(0,s.jsx)("span",{className:L.A.segmentFill,"data-testid":"dashboard-segment-fill",style:{width:`${A(c[t],n?l[t]:d)}%`},children:e.values.map((e,t)=>e&&i(a[t].label)?(0,s.jsx)("span",{className:L.A.segment,title:`${a[t].label}: ${e}`,"data-testid":"dashboard-segment",style:{flexGrow:e,backgroundColor:a[t].colour},"aria-hidden":"true"},a[t].label):null)})}),(0,s.jsx)("span",{className:L.A.segmentEnd,children:e.end})]},e.key))})]})}let es=["figures","rhdScreening","registrations"],en=(0,n.createContext)(null);function er(e,a,t,s={}){let r=(0,n.useContext)(en),i=JSON.stringify([a,s]);(0,n.useEffect)(()=>{r?.(e,a,t,s)},[r,e,i,t]),(0,n.useEffect)(()=>()=>r?.(e,[],!1,{}),[r,e])}let ei=(e,a,t,s)=>t.map(({label:t,value:n,name:r})=>({section:e,group:a,label:r??t,count:n,period:s}));var eo=t(1740),el=t(1838),ec=t(2379),ed=t(9983),eu=t(7080),em=t(4598),eh=t(8296),eg=t(1488),ep=t(3090),ef=t(1375);function eb({scope:e}){let a,{t}=(0,o.useTranslation)(),{clinicLocationTags:r}=(0,c.useConfig)(),u=(0,h.fU)(),m=(0,g.V)(r.cardiac),p=(0,g.V)(r.primaryCare),f=(0,n.useMemo)(()=>[...m,...p],[m,p]),b="ready"===u.status,x=e.primaryCareClinic||e.cardiacClinic||"",v=b?u.uuids.includes(x)?x:u.uuids[0]??"":x,j=(0,ed.P)(f,v),y="pending"===u.status||b&&!v,C=y?null:{metric:em.ml,clinic:v||null,startDate:i()().subtract(12,"month").format("YYYY-MM-DD"),endDate:i()().format("YYYY-MM-DD"),points:"week"},w=(0,ep.D)(C),N=(0,eh.cO)(w.points),A=N.length>=eh.kK?w.median:null,D=(0,n.useMemo)(()=>(0,eh.Se)(w.points,A),[w.points,A]),S=(0,em.I)(em.ml),T=(0,em.B)(t,em.ml),k=N[N.length-1],R=new URLSearchParams({metric:em.ml});return v&&R.set("clinic",v),a=b&&!v?(0,s.jsx)("p",{className:ef.A.cardNote,children:t("runChartNoClinic","No clinic on your account to chart")}):y||w.isLoading?(0,s.jsx)(l.SkeletonText,{paragraph:!0,lineCount:5}):w.error?(0,s.jsxs)("div",{className:ef.A.history,children:[(0,s.jsx)(l.InlineNotification,{kind:"error",lowContrast:!0,hideCloseButton:!0,statusIconDescription:t("errorIcon","error icon"),title:t("runChartCouldNotLoad","Could not load the run chart"),subtitle:t("restOfDashboardUpToDate","The rest of the Dashboard is up to date.")}),(0,s.jsx)(l.Button,{size:"md",onClick:()=>void w.mutate(),children:t("tryAgain","Try again")})]}):N.length<eh.UB?(0,s.jsx)(ec.X,{points:w.points,period:"week",metric:em.ml,clinic:j}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("p",{className:ef.A.cardMetric,"data-testid":"run-chart-latest",children:(0,eg.C)(t,S,k)}),null!==A&&(0,s.jsx)("p",{className:ef.A.cardNote,children:t("runChartMedianValue","Median {{value}}",{value:A})}),(0,s.jsx)(eu.c,{name:`${T}, ${j}`,points:w.points,median:A,shifts:D,period:"week",kind:S,height:"14rem",compact:!0})]}),(0,s.jsxs)(d.K,{title:t("runCharts","Run charts"),link:{label:t("openRunCharts","Open run charts"),to:`\${openmrsSpaBase}/home/act-run-charts?${R}`},children:[(0,s.jsx)("p",{className:ef.A.cardDescription,children:t("runChartsCardDescription","A clinic's figures over time, worked out from the records as they are now")}),(0,s.jsx)("h3",{className:ef.A.cardHeading,children:t("runChartTitle","{{metric}}, {{clinic}}",{metric:T,clinic:j})}),a]})}var ex=t(9184),ev=t(9610),ej=t(5802),ey=t(4026),eC=t(3361);function ew({figure:e,scope:a,asOf:t,clinicNames:r,onFigure:d,onScope:u,onAsOf:m,onBack:h}){let g,{t:p}=(0,o.useTranslation)(),{dashboard:f,careCascade:x}=(0,c.useConfig)(),v=i()().format("YYYY-MM-DD"),j=(0,n.useMemo)(()=>({endDate:t,...a,...k(e)}),[t,a,e]),{counted:y,countParams:C,pending:w}=Y(j),A=(0,b.y)(y?(g=e.figure,({registrants:f.registrantPatientsReport,waitlist:f.waitlistPatientsReport,cascade:f.cascadePatientsReport,optimisation:f.optimisationPatientsReport})[g]):null,C),{rows:D}=A,{results:S,paginationProps:T}=(0,ey.C)(D,j),O=function(e,a,t){switch(a.figure){case"registrants":return"status"===a.breakdown?{section:e("registrantStatus","Registrant status"),label:a.label}:"registered"===a.breakdown?{section:e("registered","Registered"),label:void 0}:"active"===a.breakdown?{section:e("active","Active"),label:void 0}:{section:e("activeRegistrants","Active registrants"),label:a.label};case"waitlist":return"performed"===a.breakdown?{section:e("performedInTheYear","Performed in the 12 months"),label:a.procedure}:"total"===a.breakdown?{section:e("waitingForAProcedure","Waiting for a procedure"),label:void 0}:{section:e("proceduralWaitlist","Procedural waitlist"),label:[a.procedure,a.urgency].filter(Boolean).map(a=>N(e,a)).join(", ")||void 0};case"cascade":{let s=P(a).step;return{section:e("rhdCareCascade","RHD care cascade"),label:e(t.find(({step:e})=>e===s)?.label??s)}}case"optimisation":return{section:M.includes(a.measure)?e("proceduralWaitlist","Procedural waitlist"):e("medicalOptimisation","Medical optimisation"),label:[I(e,a.measure),"notDone"!==a.outcome?void 0:M.includes(a.measure)?e("stillWaiting","Still waiting"):e("no","No")].filter(Boolean).join(", ")}}}(p,e,x.steps),F="optimisation"===e.figure?"consultations"===e.measure?"consultation":"interventions"===e.measure?"recommendation":"patient":"waitlist"===e.figure&&"total"!==e.breakdown?"recommendation":"patient",$=D.length,H={patient:p("patientsCount","{{count}} patients",{count:$}),consultation:p("consultationsCount","{{count}} consultations",{count:$}),recommendation:p("recommendationsCount","{{count}} recommendations",{count:$})},B=D.some(e=>e.figure_date),_=[p("actId","ACT ID"),p("patient","Patient"),p("age","Age"),p("sex","Sex"),p("cardiacClinic","Cardiac clinic"),p("primaryCareClinic","Primary care clinic"),"optimisation"===e.figure?I(p,e.measure):O.section,...B?[p("date","Date")]:[]],E=e=>[String(e.rhd_id??""),String(e.full_name??""),null===e.age_years||void 0===e.age_years?"":String(e.age_years),String(e.sex??""),String(e.cardiac_clinic??""),String(e.primary_care_clinic??""),String(e.figure_value??""),...B?[e.figure_date?i()(String(e.figure_date)).format("DD/MM/YYYY"):""]:[]],W=(e,a,t)=>(0,s.jsx)(l.Button,{kind:"tertiary",size:"sm",renderIcon:ex.bm,iconDescription:p("remove","Remove"),onClick:t,children:a},e);return(0,s.jsxs)("div",{className:L.A.figure,children:[(0,s.jsxs)("div",{className:L.A.figureBanner,children:[(0,s.jsx)("p",{children:p("openedFromTheDashboard","Opened from the Dashboard: {{figure}}, {{amount}}.",{figure:[O.section,O.label].filter(Boolean).join(", "),amount:H[F],interpolation:{escapeValue:!1}})}),(0,s.jsx)(l.Button,{kind:"ghost",size:"sm",renderIcon:ev.nk,onClick:h,children:p("backToTheDashboard","Back to the Dashboard")})]}),(0,s.jsxs)("div",{className:L.A.figureToolbar,children:[(0,s.jsxs)("div",{className:L.A.chips,children:[JSON.stringify(k(P(e)))!==JSON.stringify(k(P(R(e))))&&W("figure",[O.section,O.label].filter(Boolean).join(": "),()=>d(R(e))),a.cardiacClinic&&W("cardiac",`${p("cardiacClinic","Cardiac clinic")}: ${r.cardiac??""}`,()=>{let{cardiacClinic:e,...t}=a;u(t)}),a.primaryCareClinic&&W("primaryCare",`${p("primaryCareClinic","Primary care clinic")}: ${r.primaryCare??""}`,()=>{let{primaryCareClinic:e,...t}=a;u(t)}),t!==v&&W("asOf",p("asOfDate","As of {{date}}",{date:i()(t).format("DD/MM/YYYY"),interpolation:{escapeValue:!1}}),()=>m(v))]}),!A.error&&!A.isLoading&&!w&&(0,s.jsx)("div",{className:L.A.figureActions,children:(0,s.jsx)(ej.F,{name:`dashboard-${e.figure}`,list:`dashboard:${e.figure}`,identifiers:!0,filters:C,headers:_,rows:()=>D.map(E),disabled:!D.length})})]}),A.error?(0,s.jsx)(l.InlineNotification,{kind:"error",statusIconDescription:p("errorIcon","error icon"),lowContrast:!0,hideCloseButton:!0,title:p("couldNotLoadFigure","Could not load the patients behind this figure")}):A.isLoading||w?(0,s.jsx)(l.SkeletonText,{paragraph:!0,lineCount:6}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:L.A.tableContainer,children:(0,s.jsxs)(l.Table,{size:"sm","aria-label":O.section,children:[(0,s.jsx)(l.TableHead,{children:(0,s.jsx)(l.TableRow,{children:_.slice(1).map(e=>(0,s.jsx)(l.TableHeader,{children:e},e))})}),(0,s.jsx)(l.TableBody,{children:S.map((e,a)=>(0,s.jsx)(l.TableRow,{"data-testid":"dashboard-figure-row",children:E(e).slice(1).map((a,t)=>(0,s.jsx)(l.TableCell,{children:0===t?(0,s.jsx)(eC.e,{row:e}):a},_[t+1]))},`${e.patient_uuid}-${a}`))})]})}),D.length>0&&(0,s.jsx)(l.Pagination,{...T})]})]})}var eN=t(9023);function eA({counts:e,testId:a,figureOf:t,withShares:n,coloured:r}){let{t:i}=(0,o.useTranslation)(),l=K(),{isShown:c,toggle:d}=Q(e.map(e=>e.label));if(!e.length)return(0,s.jsx)("p",{className:L.A.empty,children:i("noPatientsToCount","No patients to count")});let u=Math.max(0,...e.filter(e=>c(e.label)).map(e=>e.value)),m=D(e.map(e=>e.value));return(0,s.jsx)("div",{className:L.A.bars,children:e.map((e,i)=>{let o=r&&B[e.label]||F;return(0,s.jsxs)("div",{className:n?L.A.shareBar:L.A.bar,"data-testid":a,children:[(0,s.jsx)(X,{label:l(e),colour:o,shown:c(e.label),onToggle:()=>d(e.label)}),(0,s.jsx)("span",{className:L.A.track,children:(0,s.jsx)("span",{className:L.A.fill,"data-testid":"dashboard-bar-fill",style:{width:`${c(e.label)?A(e.value,u):0}%`,backgroundColor:o}})}),(0,s.jsx)("span",{className:L.A.count,children:(0,s.jsx)(q,{value:n?e.value.toLocaleString():e.value,figure:t?.(e.label)})}),n&&(0,s.jsxs)("span",{className:L.A.share,children:[m[i],"%"]})]},e.label)})})}function eD({name:e,counts:a,testId:t,figureOf:n}){let{t:r}=(0,o.useTranslation)(),i=K(),{isShown:l,toggle:c}=Q(a.map(e=>e.label));if(!a.length)return(0,s.jsx)("p",{className:L.A.empty,children:r("noPatientsToCount","No patients to count")});let d=Math.max(0,...a.filter(e=>l(e.label)).map(e=>e.value)),u=D(a.map(e=>e.value));return(0,s.jsx)("ol",{className:L.A.columnChart,"aria-label":e,children:a.map((e,a)=>(0,s.jsxs)("li",{className:L.A.column,"data-testid":t,children:[(0,s.jsx)("span",{className:L.A.count,children:(0,s.jsx)(q,{value:e.value,figure:n?.(e.label)})}),(0,s.jsxs)("span",{className:L.A.share,children:[u[a],"%"]}),(0,s.jsx)("span",{className:L.A.columnTrack,"aria-hidden":"true",children:(0,s.jsx)("span",{className:L.A.columnFill,"data-testid":"dashboard-column-fill",style:{height:`${l(e.label)?A(e.value,d):0}%`}})}),(0,s.jsx)(X,{label:i(e),colour:F,shown:l(e.label),onToggle:()=>c(e.label),className:L.A.columnLabel})]},e.label))})}let eS="act.dashboard.collapsed";function eT({name:e,retry:a}){let{t}=(0,o.useTranslation)();return(0,s.jsxs)("div",{className:L.A.state,children:[(0,s.jsx)(l.InlineNotification,{kind:"error",statusIconDescription:t("errorIcon","error icon"),lowContrast:!0,hideCloseButton:!0,title:t("couldNotLoadSection","{{section}} could not load",{section:e}),subtitle:t("restOfDashboardUpToDate","The rest of the Dashboard is up to date.")}),(0,s.jsx)(l.Button,{size:"md",onClick:()=>a(),children:t("tryAgain","Try again")})]})}function ek({title:e,name:a=e,description:t,state:n,clinic:r,onShowAll:i,wide:c,tag:u,controls:m,emptyText:h,embedded:g,collapse:p,exportId:f,children:b}){let{t:x}=(0,o.useTranslation)(),v=(0,s.jsxs)(s.Fragment,{children:[t&&(0,s.jsx)("p",{className:L.A.description,children:t}),m,n.error?(0,s.jsx)(eT,{name:a,retry:n.retry}):n.isLoading?(0,s.jsx)(l.SkeletonText,{paragraph:!0,lineCount:5}):n.isEmpty?(0,s.jsxs)("div",{className:L.A.state,children:[(0,s.jsx)("p",{className:L.A.empty,children:h??(r?x("nobodyAtClinicToCount","Nobody at {{clinic}} to count",{clinic:r}):x("noPatientsToCount","No patients to count"))}),r&&(0,s.jsx)(l.Button,{kind:"tertiary",size:"md",onClick:i,children:x("showAllClinics","Show all clinics")})]}):b]});return g?(0,s.jsx)("div",{className:L.A.embedded,"data-print-title":e,[eo.SS]:f,children:v}):(0,s.jsx)("div",{className:c?L.A.wide:void 0,[eo.SS]:f,children:(0,s.jsx)(d.K,{title:e,tag:u,...p,children:v})})}function eR({label:e,value:a,note:t,isLoading:n,error:r,figure:i}){let{t:c}=(0,o.useTranslation)();return(0,s.jsxs)("div",{className:L.A.figureTile,"data-testid":"dashboard-tile",children:[(0,s.jsx)("span",{className:L.A.figureValue,children:n?(0,s.jsx)(l.SkeletonText,{heading:!0,width:"3rem"}):r||null===a?"–":(0,s.jsx)(q,{value:a,figure:i})}),(0,s.jsxs)("span",{className:L.A.figureText,children:[(0,s.jsx)("span",{className:L.A.figureLabel,children:e}),!n&&(0,s.jsx)("span",{className:L.A.tileNote,children:r?c("couldNotLoad","could not load"):null===a?c("notReported","not reported"):t})]})]})}function eO({container:e,showScreening:a}){let{t}=(0,o.useTranslation)(),n=(0,el.U)(),r=[["keyFigures",t("overview","Overview")],["active",n.active],["waitlist",n.waitlist],["optimisation",n.optimisation],...a?[["screening",t("screening","Screening")]]:[],["runCharts",n.runCharts]];return(0,s.jsxs)(l.Select,{id:"dashboard-jump-to",labelText:t("jumpTo","Jump to"),value:"",onChange:a=>e.current?.querySelector(`[${eo.SS}="${a.target.value}"], [data-jump="${a.target.value}"]`)?.scrollIntoView({behavior:"smooth",block:"start"}),children:[(0,s.jsx)(l.SelectItem,{value:"",text:t("chooseSection","Choose a section"),disabled:!0,hidden:!0}),r.map(([e,a])=>(0,s.jsx)(l.SelectItem,{value:e,text:a},e))]})}function eP(e){let{clinicLocationTags:a}=(0,c.useConfig)(),{sessionLocation:t}=(0,c.useSession)(),s=(0,g.V)(a.cardiac),r=(0,g.V)(a.primaryCare);return(0,n.useMemo)(()=>{let a=(e,a)=>a?e.find(e=>e.uuid===a)?.display??(a===t?.uuid?t.display:a):void 0;return{cardiac:a(s,e.cardiacClinic),primaryCare:a(r,e.primaryCareClinic)}},[s,r,e.cardiacClinic,e.primaryCareClinic,t])}let eM=(e,a)=>({isLoading:e.isLoading,error:e.error,retry:()=>void e.mutate(),isEmpty:a}),eI=e=>e.every(e=>!e.value),eY=(e,a)=>{let t=parseInt(e,10);return Number.isNaN(t)||a.filter(e=>parseInt(e,10)===t).length>1?e:String(t)},eL=["Adherent (80%+)","Adherent"],eF=["Covered today",...eL],e$="1900-01-01",eH=["retainedInCare","echocardiogram","interventionAssigned","interventions","warfarin"],eB="interventions";function e_({measures:e,name:a,testId:t,unit:n="patients"}){let{t:r}=(0,o.useTranslation)(),i="recommendations"===n;return(0,s.jsx)(et,{name:a,segments:[{label:i?r("done","Done"):r("yes","Yes"),colour:V["0"]},{label:i?r("stillWaiting","Still waiting"):r("no","No"),colour:V["1"]}],rows:e.filter(e=>null!==e.notDone).map(e=>{let a={done:e.done,notDone:e.notDone,total:e.done+e.notDone},t={done:(0,s.jsx)(q,{value:e.done,figure:{figure:"optimisation",measure:e.measure,outcome:"done"}}),notDone:(0,s.jsx)(q,{value:e.notDone,figure:{figure:"optimisation",measure:e.measure,outcome:"notDone"}})};return{key:e.measure,label:e.label,values:[e.done,e.notDone],end:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("span",{className:L.A.share,children:[A(e.done,e.done+e.notDone),"%"]}),(0,s.jsx)("span",{className:L.A.doneNotDone,children:i?(0,s.jsx)(o.Trans,{t:r,i18nKey:"doneStillWaitingOfRecommendations",defaults:"<done>{{done}}</done> done, <notDone>{{notDone}}</notDone> still waiting, of {{total}} recommendations",values:a,components:t}):(0,s.jsx)(o.Trans,{t:r,i18nKey:"yesNoOf",defaults:"<done>{{done}}</done> yes, <notDone>{{notDone}}</notDone> no, of {{total}}",values:a,components:t})})]})}}),whole:!0,testId:t})}function eE({scope:e,asOf:a,onShowAll:t}){var r;let m,{t:h}=(0,o.useTranslation)(),{careCascade:g,dashboard:p}=(0,c.useConfig)(),f=(0,n.useMemo)(()=>({endDate:a,...e}),[a,e]),x=eP(e),v=[x.cardiac,x.primaryCare].filter(Boolean).join(", ")||null,{counted:D,countParams:S,pending:T}=Y(f),k=function(){let[e,a]=(0,n.useState)(()=>{try{let e=JSON.parse(window.localStorage.getItem(eS)??"[]");return Array.isArray(e)?e:[]}catch{return[]}}),t=(0,n.useCallback)(e=>{a(a=>{let t=a.includes(e)?a.filter(a=>a!==e):[...a,e];try{window.localStorage.setItem(eS,JSON.stringify(t))}catch{}return t})},[]);return a=>({collapsed:e.includes(a),onToggle:()=>t(a)})}(),R=e=>({...e,isLoading:e.isLoading||T}),O=R((0,b.y)(D?p.registrantsReport:null,S)),P=(0,n.useMemo)(()=>{var e;let a,t;return a=C(e=O.rows,"status"),t=C(e,"age"),{status:a,sex:C(e,"sex"),age:[...t].sort((e,a)=>(j.indexOf(e.label)+1||99)-(j.indexOf(a.label)+1||99)),category:C(e,"disease").sort((e,a)=>(y.indexOf(e.label)+1||99)-(y.indexOf(a.label)+1||99)||e.label.localeCompare(a.label)),registered:a.reduce((e,a)=>e+a.value,0),active:a.find(e=>"Active"===e.label)?.value??0}},[O.rows]),F=R((0,b.y)(D?g.report:null,S)),$=a<i()().format("YYYY-MM-DD"),{cascade:H,leftOutToday:B}=(0,n.useMemo)(()=>{let e=(0,u.o)(F.rows,g.steps),a=$?e.filter(({step:e})=>!eF.includes(e)):e;return{cascade:a,leftOutToday:a.length<e.length}},[F.rows,g.steps,$]),_=(...e)=>H.find(({step:a})=>e.includes(a))?.label,V=_(...eL),K=_("Initiated","Initiated BPG"),J=R((0,b.y)(D?p.waitlistReport:null,S)),G=(0,n.useMemo)(()=>{var e;let a,t,s,n,r,i,o;return e=J.rows,a=e=>String(e??"").trim()||w,t=e.filter(e=>"open"===e.breakdown).map(e=>({procedure:a(e.procedure),urgency:a(e.urgency),recommendations:Number(e.recommendations??0)})),s=e.find(e=>"total"===e.breakdown),n=a=>Number(e.find(e=>"performed"===e.breakdown&&e.procedure===a)?.recommendations??0),r=[...new Set(t.map(e=>String(e.procedure)))].sort(),i=[...new Set(t.map(e=>String(e.urgency)))].sort((e,a)=>e.localeCompare(a,void 0,{numeric:!0})),o=r.map(e=>({procedure:e,counts:i.map(a=>t.filter(t=>t.procedure===e&&t.urgency===a).reduce((e,a)=>e+a.recommendations,0))})),{urgencies:i,rows:o,total:Number(s?.recommendations??0),patients:Number(s?.patients??0),performed:{bmv:n("Mitral balloon valvuloplasty"),surgery:n("Surgery")}}},[J.rows]),Q=(r=G.urgencies,m=e=>E[parseInt(e,10)-1],{...z(r.filter(e=>!m(e)),U),...Object.fromEntries(r.filter(m).map(e=>{let a;return[e,(a=parseInt(e,10),(r.some(t=>t!==e&&parseInt(t,10)===a)&&!/^\d+:/.test(e)?W:E)[a-1])]}))}),X="phone"===(0,c.useLayoutType)(),[Z,es]=(0,n.useState)(X),en=R((0,b.y)(D?p.medicalOptimisationReport:null,S)),el=(0,b.y)(p.showScreening?p.screeningCascadeReport:null,f),ec=(0,b.y)(p.showScreening?p.screeningDiagnosesReport:null,f),ed=en.rows.map(e=>{let a=Number(e.done??0),t=null===e.not_done||void 0===e.not_done?null:Number(e.not_done);return{measure:String(e.measure),label:I(h,String(e.measure)),done:a,notDone:t}}).sort((e,a)=>(eH.indexOf(e.measure)+1||99)-(eH.indexOf(a.measure)+1||99)),eu=ed.filter(e=>e.measure===eB),em=!!J.error&&!en.error&&eu.length>0,eh=ed.filter(e=>!M.includes(e.measure)),eg={"Confirmatory Diagnosis":h("screenedPositive","Screened positive"),Diagnosed:h("diagnosisRecorded","Diagnosis recorded"),"Heart Disease":h("heartDisease","Heart disease")},ep=el.rows.filter(e=>"Active"!==e.step).map(e=>({label:eg[String(e.step)]??String(e.step),value:Number(e.patients??0)})),ef={"Rheumatic Heart Disease/Rheumatic Fever":h("rhd","RHD"),"Congenital heart disease":h("congenital","Congenital"),"Other heart disease":h("other","Other")},ex=(e,a)=>ec.rows.filter(a=>a.breakdown===e).map(e=>({label:String(e[a]??h("none","None")),value:Number(e.patients??0)})),ev=ex("category","category").map(e=>({...e,name:ef[e.label]})),ej=ex("rhdDetails","details"),ey=ej.reduce((e,a)=>e+a.value,0),eC=(...e)=>{let a=F.rows.find(a=>e.includes(String(a.step)));return a?Number(a.patients??0):null},ew=eC("Active"),eN=eC("Prescribed","Prescribed Prophylaxis"),eO={clinic:v,onShowAll:t},e$=F.rows.find(e=>["Prescribed","Prescribed Prophylaxis"].includes(String(e.step))),eW=e=>a=>({figure:"registrants",breakdown:e,label:a}),eV=h("keyFigures","Key figures"),eU=(e,a)=>e.error?[]:a(),ez=h("proceduralWaitlist","Procedural waitlist"),eG=h("activeRegistrants","Active registrants"),eq=h("medicalOptimisationDescription","Of the {{count}} active registrants, except the warfarin row, which counts only those on warfarin",{count:P.active}),eQ=(e,t,[s,n])=>t.flatMap(t=>ei(e,t.label,null===t.notDone?[{label:"",value:t.done}]:[{label:s,value:t.done},{label:n,value:t.notDone}],a));return er("figures",[...eU(O,()=>ei(eV,"",[{label:h("registered","Registered"),value:P.registered},{label:h("active","Active"),value:P.active}],a)),...eU(F,()=>null===eN?[]:ei(eV,"",[{label:h("onSecondaryProphylaxis","On secondary prophylaxis"),value:eN}],a)),...eU(J,()=>ei(eV,"",[{label:h("waitingForAProcedure","Waiting for a procedure"),value:G.patients},{label:h("openRecommendationsFigure","Open recommendations"),value:G.total}],a)),...eU(O,()=>ei(h("registrantStatus","Registrant status"),"",P.status,a)),...eU(F,()=>ei(h("rhdCareCascade","RHD care cascade"),"",H.map(({label:e,value:a})=>({label:h(e),value:a})),a)),...eU(O,()=>[...ei(eG,h("sex","Sex"),P.sex,a),...ei(eG,h("age","Age"),P.age,a),...ei(eG,h("disease","Disease"),P.category,a)]),...eU(J,()=>[...G.rows.flatMap(e=>ei(ez,N(h,e.procedure),e.counts.map((e,a)=>({label:N(h,G.urgencies[a]),value:e})),a))]),...eU(en,()=>eQ(ez,eu,[h("done","Done"),h("stillWaiting","Still waiting")])),...eU(J,()=>[...ei(ez,h("performedLast12Months","Performed in the last 12 months"),[{label:h("mitralBalloonValvuloplasty","Mitral balloon valvuloplasty"),value:G.performed.bmv},{label:h("surgery","Surgery"),value:G.performed.surgery}],a)]),...eU(en,()=>eQ(h("medicalOptimisation","Medical optimisation"),eh,[h("yes","Yes"),h("no","No")])),...!p.showScreening||el.error||ec.error?[]:[...ei(h("screeningCascade","Screening cascade"),h("cascade","Cascade"),ep,a),...ei(h("screeningCascade","Screening cascade"),h("whatTheDiagnosisFound","What the diagnosis found"),ev,a),...ei(h("screeningCascade","Screening cascade"),h("rhdDetails","RHD details"),ej,a)]],[O,F,J,en].some(e=>e.isLoading)||el.isLoading||ec.isLoading),(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:L.A.figures,[eo.SS]:"keyFigures",children:[(0,s.jsx)(eR,{label:h("registered","Registered"),value:P.registered,note:h("everyStatus","every status"),isLoading:O.isLoading,error:O.error,figure:{figure:"registrants",breakdown:"registered"}}),(0,s.jsx)(eR,{label:h("active","Active"),value:P.active,note:h("enrolledAndAlive","enrolled and alive"),isLoading:O.isLoading,error:O.error,figure:{figure:"registrants",breakdown:"active"}}),(0,s.jsx)(eR,{label:h("onSecondaryProphylaxis","On secondary prophylaxis"),value:eN,note:null===ew?h("activeRhdNotReported","active RHD not reported"):h("shareOfActiveRhd","{{share}}% of active RHD",{share:A(eN??0,ew)}),isLoading:F.isLoading,error:F.error,figure:e$&&{figure:"cascade",step:String(e$.step)}}),(0,s.jsx)(eR,{label:h("waitingForAProcedure","Waiting for a procedure"),value:G.patients,note:h("openRecommendations","{{count}} open recommendations",{count:G.total}),isLoading:J.isLoading,error:J.error,figure:{figure:"waitlist",breakdown:"total"}})]}),(0,s.jsxs)("div",{className:L.A.grid,children:[(0,s.jsx)(ek,{title:h("registrantStatus","Registrant status"),description:h("registrantsByStatus","All {{count}} registrants, by where their registration stands",{count:P.registered}),state:eM(O,!P.registered),collapse:k("status"),exportId:"status",...eO,children:(0,s.jsx)(ee,{name:h("registrantStatus","Registrant status"),counts:P.status,centre:h("registrants","registrants"),testId:"dashboard-status",withShare:!0,figureOf:eW("status")})}),(0,s.jsx)(ek,{title:h("rhdCareCascade","RHD care cascade"),description:B?h("careCascadePastDescription","Active RHD patients; each step is a share of the one before. Coverage and adherence are left out, as ACT Core keeps them only for today."):h("careCascadeDescription","Active RHD patients; each step is a share of the one before, Adherent of Initiated"),state:eM(F,eI(H)),collapse:k("cascade"),exportId:"cascade",...eO,children:(0,s.jsx)(ea,{name:h("rhdCareCascade","RHD care cascade"),steps:H,shareOf:V&&K?{[V]:K}:void 0,testId:"dashboard-cascade-step",figureOf:e=>({figure:"cascade",step:H.find(a=>a.label===e)?.step})})}),(0,s.jsx)(ek,{title:h("activeRegistrantsCount","Active registrants: {{count}}",{count:P.active}),name:h("activeRegistrants","Active registrants"),description:h("activeRegistrantsDescription","Sex, age and disease of the patients active today"),state:eM(O,!P.active),wide:!0,collapse:k("active"),exportId:"active",...eO,children:(0,s.jsxs)("div",{className:L.A.columns,children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:L.A.subheading,children:h("sex","Sex")}),(0,s.jsx)(ee,{name:h("sex","Sex"),counts:P.sex,centre:h("activeCentre","active"),testId:"dashboard-sex",withShare:!0,figureOf:eW("sex")})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:L.A.subheading,children:h("age","Age")}),(0,s.jsx)(eD,{name:h("age","Age"),counts:P.age,testId:"dashboard-age",figureOf:eW("age")})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:L.A.subheading,children:h("disease","Disease")}),(0,s.jsx)(eA,{counts:P.category,testId:"dashboard-category",figureOf:eW("disease"),coloured:!0})]})]})}),(0,s.jsxs)(ek,{title:O.error?h("proceduralWaitlistPatients","Procedural waitlist: {{count}} patients",{count:G.patients}):h("proceduralWaitlistOfActive","Procedural waitlist: {{count}} of {{active}} active patients are waiting for a procedure",{count:G.patients,active:P.active}),name:h("proceduralWaitlist","Procedural waitlist"),description:h("waitlistDescription","Open recommendations in each active patient's latest consultation, by urgency"),state:em?eM(en,!1):eM(J,!G.total&&!G.performed.bmv&&!G.performed.surgery&&!en.error&&eu.every(e=>!e.done&&!e.notDone)),wide:!0,collapse:k("waitlist"),exportId:"waitlist",...eO,children:[em?(0,s.jsx)(eT,{name:ez,retry:()=>void J.mutate()}):Z?(0,s.jsxs)("div",{className:L.A.tableContainer,children:[(0,s.jsxs)(l.Table,{size:"sm","aria-label":h("proceduralWaitlist","Procedural waitlist"),children:[(0,s.jsx)(l.TableHead,{children:(0,s.jsxs)(l.TableRow,{children:[(0,s.jsx)(l.TableHeader,{children:h("procedure","Procedure")}),G.urgencies.map(e=>(0,s.jsx)(l.TableHeader,{children:X?eY(e,G.urgencies):N(h,e)},e))]})}),(0,s.jsx)(l.TableBody,{children:G.rows.map(e=>(0,s.jsxs)(l.TableRow,{"data-testid":"dashboard-waitlist-row",children:[(0,s.jsx)(l.TableCell,{children:N(h,e.procedure)}),e.counts.map((a,t)=>(0,s.jsx)(l.TableCell,{children:(0,s.jsx)(q,{value:a,figure:a?{figure:"waitlist",breakdown:"open",procedure:e.procedure,urgency:G.urgencies[t]}:void 0})},G.urgencies[t]))]},e.procedure))})]}),X&&G.urgencies.some(e=>eY(e,G.urgencies)!==e)&&(0,s.jsx)("p",{className:L.A.performed,children:G.urgencies.map(e=>N(h,e)).join(", ")})]}):(0,s.jsx)(et,{name:h("urgency","Urgency"),segments:G.urgencies.map(e=>({label:N(h,e),colour:Q[e]})),rows:G.rows.map(e=>({key:e.procedure,label:N(h,e.procedure),values:e.counts,end:(0,s.jsx)("span",{className:L.A.count,children:(0,s.jsx)(q,{value:e.counts.reduce((e,a)=>e+a,0),figure:{figure:"waitlist",breakdown:"open",procedure:e.procedure}})})})),testId:"dashboard-waitlist-total"}),en.error?(0,s.jsx)("p",{className:L.A.performed,children:h("waitlistFigureCouldNotLoad","{{figure}} could not load",{figure:I(h,eB)})}):eu.length>0&&(0,s.jsx)(s.Fragment,{children:(0,s.jsx)(e_,{measures:eu,name:h("recommendationOutcome","Recommendation outcome"),testId:"dashboard-procedure-measure",unit:"recommendations"})}),!em&&(0,s.jsxs)("div",{className:L.A.sectionFooter,children:[(0,s.jsx)("p",{className:L.A.performed,"data-testid":"dashboard-performed",children:(0,s.jsx)(o.Trans,{t:h,i18nKey:"performedInYear",defaults:"Performed in the 12 months to the date shown: mitral balloon valvuloplasty <bmv>{{bmv}}</bmv>, surgery <surgery>{{surgery}}</surgery>",values:G.performed,components:{bmv:(0,s.jsx)(q,{value:G.performed.bmv,figure:{figure:"waitlist",breakdown:"performed",procedure:"Mitral balloon valvuloplasty"}}),surgery:(0,s.jsx)(q,{value:G.performed.surgery,figure:{figure:"waitlist",breakdown:"performed",procedure:"Surgery"}})}})}),(0,s.jsx)(l.Button,{kind:"ghost",size:"sm",onClick:()=>es(!Z),children:Z?h("showAsAChart","Show as a chart"):h("showAsATable","Show as a table")})]})]}),(0,s.jsxs)(ek,{title:h("medicalOptimisation","Medical optimisation"),description:eq,state:eM(en,eh.every(e=>!e.done&&!e.notDone)),wide:!0,collapse:k("optimisation"),exportId:"optimisation",...eO,children:[(0,s.jsx)(e_,{measures:eh,name:h("outcome","Outcome"),testId:"dashboard-measure"}),eh.filter(e=>null===e.notDone).map(e=>(0,s.jsxs)("p",{className:L.A.sectionFooter,"data-testid":"dashboard-measure-count",children:[(0,s.jsx)("span",{className:L.A.performed,children:e.label}),(0,s.jsx)("span",{className:L.A.count,children:(0,s.jsx)(q,{value:e.done,figure:{figure:"optimisation",measure:e.measure}})})]},e.measure))]}),p.showScreening&&(0,s.jsx)("div",{className:`${L.A.wide} ${L.A.keepTogether}`,"data-jump":"screening","data-export-card":"",children:(0,s.jsx)(d.K,{...k("screening"),title:h("screening","Screening"),tag:(0,s.jsx)(l.Tag,{type:"cool-gray",size:"sm",children:h("screeningProgrammeSites","Screening programme sites")}),children:(0,s.jsxs)(l.Tabs,{children:[(0,s.jsxs)(l.TabList,{"aria-label":h("screening","Screening"),children:[(0,s.jsx)(l.Tab,{children:h("screeningCascade","Screening cascade")}),(0,s.jsx)(l.Tab,{children:h("screeningCounts","Screening counts")}),(0,s.jsx)(l.Tab,{children:h("screeningFromRegistrations","Screening, from registrations")})]}),(0,s.jsxs)(l.TabPanels,{children:[(0,s.jsx)(l.TabPanel,{children:(0,s.jsx)(ek,{title:h("screeningCascade","Screening cascade"),description:h("screeningCascadeDescription","Registrants found by screening (Screen + Yes), and the diagnosis each was given"),state:{isLoading:el.isLoading||ec.isLoading,error:el.error??ec.error,retry:()=>{el.error&&el.mutate(),ec.error&&ec.mutate()},isEmpty:eI(ep)&&eI(ev)},embedded:!0,exportId:"screeningCascade",...eO,children:(0,s.jsxs)("div",{className:L.A.columns,children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:L.A.subheading,children:h("cascade","Cascade")}),(0,s.jsx)(ea,{name:h("screeningCascade","Screening cascade"),steps:ep,testId:"dashboard-screening-step"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:L.A.subheading,children:h("whatTheDiagnosisFound","What the diagnosis found")}),(0,s.jsx)(ee,{name:h("whatTheDiagnosisFound","What the diagnosis found"),counts:ev,centre:h("diagnosed","diagnosed"),testId:"dashboard-screening-category"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:L.A.subheading,children:h("screenDetectedRhd","RHD details of the {{count}}",{count:ey})}),(0,s.jsx)(eA,{counts:ej,testId:"dashboard-screening-details",coloured:!0})]})]})})}),(0,s.jsx)(l.TabPanel,{children:(0,s.jsx)(eJ,{scope:e,...eO})}),(0,s.jsx)(l.TabPanel,{children:(0,s.jsx)(eK,{scope:e,asOf:a,...eO})})]})]})})}),(0,s.jsx)("div",{className:L.A.wide,children:(0,s.jsx)("div",{[eo.SS]:"runCharts",children:(0,s.jsx)(eb,{scope:e})})})]})]})}let eW=["Yes","No","Not recorded"],eV=["Children 0-9","Adolescents 10-19","Adults 20+","Age unknown"],eU=["School","Community","Health facility","Clinical presentation","Pregnancy / labor","Coincidental finding","Post-mortem","Other","Not recorded","Not screen-positive"],ez=(e,a,t)=>e.filter(e=>e.breakdown===a).map(e=>({label:String(e.label),value:Number(e.patients??0)})).sort((e,a)=>(t.indexOf(e.label)+1||99)-(t.indexOf(a.label)+1||99));function eK({scope:e,asOf:a,clinic:t,onShowAll:r}){let{t:d}=(0,o.useTranslation)(),{dashboard:u}=(0,c.useConfig)(),[m,h]=(0,n.useState)({}),g=m.end??a,p=m.start&&m.start<=g?m.start:i()(g).subtract(364,"day").format("YYYY-MM-DD"),{counted:f,countParams:x,pending:v}=Y((0,n.useMemo)(()=>({startDate:p,endDate:g,...e}),[p,g,e])),j=(0,b.y)(f?u.screeningReport:null,x),{rows:y}=j,C=Number(y.find(e=>"total"===e.breakdown)?.patients??0),w=Number(y.find(e=>"female"===e.breakdown)?.patients??0),N=e=>a=>{let t=a&&i()(a).format("YYYY-MM-DD");t&&t>=e$&&h(a=>({...a,[e]:t}))},D=d("screeningFromRegistrations","Screening, from registrations"),S=d("periodRange","{{start}} to {{end}}",{start:p,end:g});return er("registrations",j.error?[]:[...ei(D,"",[{label:d("registered","Registered"),value:C},{label:d("female","Female"),value:w}],S),...ei(D,d("screenPlus","Screen +"),ez(y,"screen",eW),S),...ei(D,d("ageAtRegistration","Age at registration"),ez(y,"age",eV),S),...ei(D,d("caseDetectedBy","Case detected by"),ez(y,"detected",eU),S)],j.isLoading||v,{registeredFrom:p,registeredTo:g}),(0,s.jsx)(ek,{title:d("screeningFromRegistrations","Screening, from registrations"),description:d("screeningFromRegistrationsDescription","Patients registered in the period: what the registry itself can say about screening"),state:{...eM(j,!C),isLoading:j.isLoading||v},clinic:t,onShowAll:r,embedded:!0,exportId:"registrations",controls:(0,s.jsxs)("div",{className:L.A.registrationControls,children:[(0,s.jsx)(l.InlineNotification,{kind:"info",statusIconDescription:d("infoIcon","info icon"),lowContrast:!0,hideCloseButton:!0,title:d("registrationsNotScreening","Counts registered patients, not people screened: a screen-negative child is never registered.")}),(0,s.jsxs)("div",{className:L.A.filters,children:[(0,s.jsx)(c.OpenmrsDatePicker,{id:"dashboard-registered-from",labelText:d("registeredFrom","Registered from"),value:i()(p).toDate(),minDate:i()(e$).toDate(),maxDate:i()(g).toDate(),onChange:N("start")}),(0,s.jsx)(c.OpenmrsDatePicker,{id:"dashboard-registered-to",labelText:d("registeredTo","Registered to"),value:i()(g).toDate(),minDate:i()(p).toDate(),maxDate:new Date,onChange:N("end")})]})]}),children:(0,s.jsxs)("div",{className:L.A.columns,children:[(0,s.jsxs)("div",{className:L.A.registrationTiles,children:[(0,s.jsxs)("div",{className:L.A.registrationPair,children:[(0,s.jsxs)(l.Tile,{className:L.A.tile,"data-testid":"dashboard-registration-tile",children:[(0,s.jsx)("span",{className:L.A.tileLabel,children:d("registered","Registered")}),(0,s.jsx)("span",{className:L.A.tileValue,children:C})]}),(0,s.jsxs)(l.Tile,{className:L.A.tile,"data-testid":"dashboard-registration-tile",children:[(0,s.jsx)("span",{className:L.A.tileLabel,children:d("female","Female")}),(0,s.jsxs)("span",{className:L.A.tileValue,children:[A(w,C),"%"]})]})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:L.A.subheading,children:d("screenPlus","Screen +")}),(0,s.jsx)(eA,{counts:ez(y,"screen",eW),testId:"dashboard-screen-positive"})]})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:L.A.subheading,children:d("ageAtRegistration","Age at registration")}),(0,s.jsx)(eA,{counts:ez(y,"age",eV),testId:"dashboard-registration-age"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:L.A.subheading,children:d("caseDetectedBy","Case detected by")}),(0,s.jsx)(ee,{name:d("caseDetectedBy","Case detected by"),counts:ez(y,"detected",eU),centre:d("registeredCentre","registered"),testId:"dashboard-detected"}),(0,s.jsx)("p",{className:L.A.note,children:d("notScreenPositiveNote","Patient Information asks where a patient was screened only when Screen + is Yes. Not screen-positive counts the patients never asked; Not recorded, the screen-positive with no answer.")})]})]})})}function eJ({scope:e,clinic:a,onShowAll:t}){let{t:r}=(0,o.useTranslation)(),c=(0,n.useMemo)(()=>(0,eN.$9)(eN.t3),[]),{settingLabel:d,metricLabel:u}=(0,eN.NH)(),[m,g]=(0,n.useState)({}),p=m.end??c[1],f=i()(`${p}-01`).subtract(11,"month").format("YYYY-MM"),b=c[c.length-1],x=m.start&&m.start<=p?m.start:f<b?b:f,v=(0,h.fU)(),j="none"===v.status||"ready"===v.status&&v.uuids.length>0,y="pending"===v.status,C=(0,n.useMemo)(()=>j?{clinics:Object.values(e),startMonth:x,endMonth:p}:null,[j,e,x,p]),{summary:w,error:N,isLoading:D,mutate:S}=(0,eN.Y9)(C),T=w?.screened??0,k=new Set(Object.values(e)).size||("ready"===v.status?v.uuids.length:0),R=k*(i()(`${p}-01`).diff(i()(`${x}-01`),"month")+1),O=w?.months??0,P=k>0&&O<R,M=k?P?k>1?r("screeningMonthsEnteredAcross","Counts entered for {{entered}} of {{expected}} months across {{clinics}} clinics. A month not entered adds nothing to these figures.",{entered:O,expected:R,clinics:k}):r("screeningMonthsEnteredOf","Counts entered for {{entered}} of {{expected}} months. A month not entered adds nothing to these figures.",{entered:O,expected:R}):r("screeningMonthsAllEntered","Counts entered for every month in the period"):r("screeningMonthsEnteredEveryClinic","Counts entered for {{count}} months across all clinics",{count:O}),I=(e,a,t,n,r)=>(0,s.jsx)(l.Select,{id:e,labelText:a,value:t,onChange:e=>g(a=>({...a,[n]:e.target.value})),children:r.map(e=>(0,s.jsx)(l.SelectItem,{value:e,text:(0,eN.g6)(e)},e))}),Y=r("clinicsAddedTogether","{{clinics}} added together",{clinics:a}),F=(Object.keys(e).length>1?Y:a)??("ready"===v.status?v.names.join(", ")||r("yourClinics","your clinics"):r("everyClinic","every clinic")),$=r("screeningCounts","Screening counts"),H=r("periodRange","{{start}} to {{end}}",{start:x,end:p});return er("rhdScreening",N||!w?[]:[...ei($,"",[{label:r("monthsEntered","Months entered"),value:O},{label:u.screened,value:T},{label:u.females,value:w.females??0},{label:u.positive,value:w.positive??0}],H),...ei($,r("result","Result"),[{label:r("negative","Negative"),value:w.negative??0},{label:u.positive,value:w.positive??0}],H),...ei($,r("age","Age"),[{label:u.children,value:w.children??0},{label:u.adolescents,value:w.adolescents??0},{label:u.adults,value:w.adults??0}],H),...ei($,r("setting","Setting"),eN.W0.map(e=>({label:d[e],value:w.settings?.[e]??0})),H)],D||y,{screeningFromMonth:x,screeningToMonth:p}),(0,s.jsxs)(ek,{title:r("screeningCounts","Screening counts"),description:r("rhdScreeningDescription","Monthly counts, {{clinic}}, {{start}} to {{end}}",{clinic:F,start:(0,eN.g6)(x),end:(0,eN.g6)(p)}),state:{isLoading:D||y,error:N,retry:()=>void S(),isEmpty:!w?.months},clinic:a,onShowAll:t,embedded:!0,exportId:"rhdScreening",emptyText:a?r("noScreeningCountsAt","No screening counts entered for {{clinic}} in the period",{clinic:a}):r("noScreeningCounts","No screening counts entered in the period"),wide:!0,controls:(0,s.jsxs)("div",{className:L.A.filters,children:[I("dashboard-screening-from",r("fromMonth","From"),x,"start",c.filter(e=>e<=p)),I("dashboard-screening-to",r("toMonth","To"),p,"end",c)]}),children:[P?(0,s.jsx)(l.InlineNotification,{kind:"warning",statusIconDescription:r("warningIcon","warning icon"),lowContrast:!0,hideCloseButton:!0,className:L.A.screeningCoverage,title:M,"data-testid":"dashboard-screening-coverage"}):(0,s.jsx)("p",{className:L.A.screeningCoverage,"data-testid":"dashboard-screening-coverage",children:M}),(0,s.jsxs)("div",{className:L.A.screeningTiles,children:[(0,s.jsxs)(l.Tile,{className:L.A.tile,"data-testid":"dashboard-screening-tile",children:[(0,s.jsx)("span",{className:L.A.tileLabel,children:u.screened}),(0,s.jsx)("span",{className:L.A.tileValue,children:T.toLocaleString()})]}),(0,s.jsxs)(l.Tile,{className:L.A.tile,"data-testid":"dashboard-screening-tile",children:[(0,s.jsx)("span",{className:L.A.tileLabel,children:u.females}),(0,s.jsxs)("span",{className:L.A.tileValue,children:[A(w?.females??0,T),"%"]})]}),(0,s.jsxs)(l.Tile,{className:L.A.tile,"data-testid":"dashboard-screening-tile",children:[(0,s.jsx)("span",{className:L.A.tileLabel,children:u.positive}),(0,s.jsx)("span",{className:L.A.tileValue,children:(w?.positive??0).toLocaleString()})]})]}),(0,s.jsxs)("div",{className:L.A.columns,children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:L.A.subheading,children:r("result","Result")}),(0,s.jsx)(eA,{withShares:!0,counts:[{label:r("negative","Negative"),value:w?.negative??0},{label:u.positive,value:w?.positive??0}],testId:"dashboard-screening-result"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:L.A.subheading,children:r("age","Age")}),(0,s.jsx)(eA,{withShares:!0,counts:[{label:u.children,value:w?.children??0},{label:u.adolescents,value:w?.adolescents??0},{label:u.adults,value:w?.adults??0}],testId:"dashboard-screening-age"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:L.A.subheading,children:r("setting","Setting")}),(0,s.jsx)(eA,{withShares:!0,counts:eN.W0.map(e=>({label:d[e],value:w?.settings?.[e]??0})),testId:"dashboard-screening-setting"})]})]}),(0,s.jsx)("p",{className:L.A.note,children:r("sharesAddUpTo100","Shares are rounded so each group adds up to 100%.")})]})}let eG=["cardiacClinic","primaryCareClinic","asOf",...T],eq=Object.fromEntries(T.map(e=>[e,""]));function eQ(){let{t:e}=(0,o.useTranslation)(),a=(0,f.G)(!1),[t,r,d]=(0,x.y)(eG,"ready"===a.status?a.params:"error"===a.status?{}:"pending"),u=i()().format("YYYY-MM-DD"),g=t.asOf||u,b=e=>r({asOf:e===u?"":e}),v=(0,n.useMemo)(()=>d?void 0:Object.fromEntries(Object.entries({cardiacClinic:t.cardiacClinic,primaryCareClinic:t.primaryCareClinic}).filter(([,e])=>e)),[d,t.cardiacClinic,t.primaryCareClinic]),j=(0,n.useCallback)(e=>r({cardiacClinic:e.cardiacClinic??"",primaryCareClinic:e.primaryCareClinic??""}),[r]),y=(0,n.useMemo)(()=>S.includes(t.figure)?Object.fromEntries(T.map(e=>[e,t[e]])):null,[t]),C="ready"===a.status?Object.keys(a.params):[],w=e=>(0,x.j)(eG,{...t,...e},C),N=e=>{window.history.pushState(window.history.state,"",w(e)),r(e)},A=eP(v??{}),[D,k]=(0,n.useState)({}),R=(0,n.useCallback)((e,a,t,s)=>k(n=>({...n,[e]:{rows:a,isLoading:t,filters:s}})),[]),P=es.flatMap(e=>D[e]?.rows??[]),M=(0,n.useRef)(null),I=(0,c.useSession)(),{dashboard:Y}=(0,c.useConfig)(),F=Y.showScreening,$=(0,h.fU)(),H=[A.cardiac,A.primaryCare].filter(Boolean).join(", ")||("ready"===$.status?$.names.join(", ")||e("yourClinics","your clinics"):e("everyClinic","every clinic"));return(0,s.jsxs)("div",{className:L.A.page,ref:M,children:[(0,s.jsx)("div",{className:L.A.noPrint,children:(0,s.jsx)(m.r,{title:e("dashboard","Dashboard"),illustration:(0,s.jsx)(c.ReportsPictogram,{})})}),(0,s.jsxs)("header",{className:L.A.printHeader,children:[(0,s.jsx)("h1",{children:e("dashboard","Dashboard")}),(0,s.jsxs)("p",{children:[H," \xb7"," ",e("figuresAsOfDate","figures as of {{date}}",{date:(0,c.formatDate)(i()(g).toDate(),{time:!1,noToday:!0})})]}),(0,s.jsxs)("p",{children:[e("printedByOn","Printed by {{user}} on {{date}}",{user:I?.user?.person?.display??I?.user?.display??"",date:(0,c.formatDate)(new Date,{noToday:!0})})," \xb7 ",e("countsOnlyNoPatients","Counts only, no patient data")]})]}),(0,s.jsx)("div",{className:L.A.content,children:"error"===a.status?(0,s.jsx)(l.InlineNotification,{kind:"error",statusIconDescription:e("errorIcon","error icon"),lowContrast:!0,hideCloseButton:!0,title:e("couldNotLoadDashboard","Could not load the dashboard")}):v?y?(0,s.jsx)(ew,{figure:y,scope:v,asOf:g,clinicNames:A,onFigure:e=>r({...eq,...e}),onScope:j,onAsOf:b,onBack:()=>N(eq)}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:`${L.A.filters} ${L.A.toolbar} ${L.A.noPrint}`,children:[(0,s.jsx)(p.QF,{scope:v,onChange:j,idPrefix:"dashboard"}),(0,s.jsx)(c.OpenmrsDatePicker,{id:"dashboard-as-of",labelText:e("figuresAsOf","Figures as of"),value:i()(g).toDate(),minDate:i()(e$).toDate(),maxDate:new Date,onChange:e=>{let a=e&&i()(e).format("YYYY-MM-DD");a&&a>=e$&&b(a)}}),(0,s.jsxs)("div",{className:L.A.download,children:[(0,s.jsx)(eO,{container:M,showScreening:F}),(0,s.jsx)(el.B,{container:M,csvRows:P,csvLoading:es.some(e=>D[e]?.isLoading),filters:{endDate:g,...v},sectionFilters:{rhdScreening:D.rhdScreening?.filters,registrations:D.registrations?.filters},clinics:H,asOf:g,showScreening:F})]})]}),(0,s.jsx)(O.Provider,{value:{href:e=>w({...eq,...e}),open:e=>N({...eq,...e})},children:(0,s.jsx)(en.Provider,{value:R,children:(0,s.jsx)(eE,{scope:v,asOf:g,onShowAll:()=>j({})})})})]}):(0,s.jsx)(l.SkeletonText,{paragraph:!0,lineCount:6})})]})}},3361(e,a,t){t.d(a,{e:()=>i});var s=t(7858);t(4335);var n=t(6144),r=t(9342);function i({row:e,to:a,detail:t,children:o}){let l=String(e.rhd_id??"");return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.ConfigurableLink,{to:a??(0,r.z)(e.patient_uuid),children:String(e.full_name??"")}),o,(0,s.jsx)("span",{className:"-esm-act__patient-cell__actId___l5w3T",children:[l,t].filter(Boolean).join(" \xb7 ")})]})}},9342(e,a,t){t.d(a,{z:()=>s});let s=e=>`\${openmrsSpaBase}/patient/${e}/chart`},9023(e,a,t){t.d(a,{$9:()=>g,NH:()=>f,QI:()=>v,W0:()=>c,Y9:()=>j,fi:()=>m,g6:()=>p,qd:()=>d,t3:()=>h,ws:()=>x});var s=t(8406),n=t.n(s),r=t(1943),i=t(3483),o=t.n(i),l=t(6144);let c=["school","community","facility"],d=["screened","children","adolescents","adults","females","positive"],u=`${l.restBaseUrl}/actcore/screeningcounts`,m=(e,a)=>`${e}_${a}`,h=36,g=e=>Array.from({length:e},(e,a)=>n()().subtract(a,"month").format("YYYY-MM")),p=e=>n()(`${e}-01`).format("MMMM YYYY");function f(){let{t:e}=(0,r.useTranslation)();return{settingLabel:{school:e("school","School"),community:e("community","Community"),facility:e("healthFacility","Health facility")},metricLabel:{screened:e("screened","Screened"),children:e("children0to9","Children 0-9"),adolescents:e("adolescents10to19","Adolescents 10-19"),adults:e("adults20plus","Adults 20+"),females:e("female","Female"),positive:e("positive","Positive")}}}let b=(e,a)=>`${u}?clinic=${encodeURIComponent(e)}&month=${encodeURIComponent(a)}`;function x(e,a){let t=e&&a?b(e,a):null,{data:s,error:n,isLoading:r,mutate:i}=o()(t,async e=>(await (0,l.openmrsFetch)(e)).data,{revalidateOnFocus:!1,revalidateOnReconnect:!1});return{month:s,error:n,isLoading:r,mutate:i}}async function v(e,a,t,s,n){let r=b(e,a),{data:i}=await (0,l.openmrsFetch)(r,{method:"POST",headers:{"Content-Type":"application/json"},body:{counts:t,notes:s}});await n(r,i,{revalidate:!1})}function j(e){let a=e?`${u}/summary?${[...e.clinics.map(e=>`clinic=${encodeURIComponent(e)}`),`startMonth=${e.startMonth}`,`endMonth=${e.endMonth}`].join("&")}`:null,{data:t,error:s,isLoading:n,mutate:r}=o()(a,async e=>(await (0,l.openmrsFetch)(e)).data,{shouldRetryOnError:!1});return{summary:t,error:s,isLoading:n,mutate:r}}},5802(e,a,t){t.d(a,{F:()=>p});var s=t(7858),n=t(4335),r=t(8406),i=t.n(r),o=t(1943),l=t(6204),c=t(771),d=t(6144),u=t(7003),m=t(3571),h=t(1047),g=t(3531);function p({name:e,list:a,identifiers:t,filters:r={},headers:f,rows:b,disabled:x,size:v="sm"}){let{t:j}=(0,o.useTranslation)(),[y,C]=(0,n.useState)(!1),w=async()=>{let s;C(!0);try{s=await b()}catch(e){(0,d.showSnackbar)({kind:"error",title:j("couldNotBuildFile","Could not build the file"),subtitle:(0,h.e)(e)}),C(!1);return}try{await (0,m.kt)({list:a,columns:f,rows:s.length,identifiers:t,filters:r}),(0,g.t)(`${e}-${i()().format("YYYY-MM-DD")}.csv`,f,s)}catch(e){(0,d.showSnackbar)({kind:"error",title:j("couldNotRecordDownload","Could not record the download, so no file was made"),subtitle:(0,h.e)(e)})}finally{C(!1)}};return(0,s.jsx)(d.UserHasAccess,{privilege:u.z$,children:(0,s.jsx)(l.Button,{kind:"tertiary",size:v,renderIcon:c.f5,disabled:x||y,onClick:w,children:y?(0,s.jsx)(l.InlineLoading,{description:j("downloading","Downloading...")}):j("downloadCsv","Download CSV")})})}},4026(e,a,t){t.d(a,{C:()=>o});var s=t(4335),n=t(6144),r=t(4623);let i=[10,25,50,100];function o(e,a){let[t,o]=(0,s.useState)(i[0]),{results:l,currentPage:c,goTo:d}=(0,n.usePagination)(e,t),u=(0,r.T)();return(0,s.useEffect)(()=>d(1),[a,d]),{results:l,paginationProps:{...u,page:c,pageSize:t,pageSizes:i,totalItems:e.length,onChange:({page:e,pageSize:a})=>{o(a),d(e)}}}}},4623(e,a,t){t.d(a,{T:()=>r});var s=t(1943),n=t(6144);function r(){let{t:e}=(0,s.useTranslation)();return{backwardText:e("previousPage","Previous page"),forwardText:e("nextPage","Next page"),itemsPerPageText:e("itemsPerPage","Items per page:"),itemRangeText:(a,t,s)=>e("itemRange","{{min}}–{{max}} of {{count}} items",{min:a,max:t,count:s}),pageRangeText:(e,a)=>(0,n.getCoreTranslation)("paginationOfPages","of {{count}} pages",{count:a})}}}}]);