@act-registry/esm-act-app 1.0.1-pre.629 → 1.0.1-pre.644
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 +1 -1
- package/dist/3889.js.map +1 -1
- package/dist/5117.js +1 -1
- package/dist/5117.js.map +1 -1
- package/dist/act-registry-esm-act-app.js +1 -1
- package/dist/routes.json +1 -1
- package/package.json +1 -1
- package/src/dashboard/dashboard-figure.ts +11 -3
- package/src/dashboard/dashboard.component.tsx +19 -15
- package/src/dashboard/dashboard.test.tsx +20 -18
- package/translations/en.json +8 -9
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),r=t(4335),n=t(8406),i=t.n(n),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 A="Not given",N=(e,a)=>a===A?e("notGiven","Not given"):a,w=(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),r=100-s.reduce((e,a)=>e+a,0),n=t.map((e,a)=>({index:a,remainder:e-s[a]}));return n.sort((e,a)=>a.remainder-e.remainder||e.index-a.index),n.slice(0,r).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,r.createContext)(null),P=e=>"cascade"===e.figure?{...e,step:e.step||"Active"}:e,M=["interventionAssigned","interventions"];function I(e,a){return({consultations:e("consultationsLastYear","Consultations in the last year"),echocardiogram:e("echoLast13Months","Echocardiogram in the last 13 months"),retainedInCare:e("retainedInCare","Retained in care (seen 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,r.useMemo)(()=>t?.length?{...e,clinics:t.join(",")}:e,[e,t]),pending:"pending"===a.status}}var L=t(1327);let F="#009d9a",H="#c6c6c6",$="#007d79",B={Active:F,"Lost to follow-up":"#da1e28","Voluntary inactivity":"#ba4e00","Physical relocation":"#6f6f6f",Deceased:"#161616","Rheumatic Heart Disease/Rheumatic Fever":$,"Acute rheumatic fever":"#08bdba","RHD A":F,"RHD B":$,"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":H,"No status recorded":H,"No diagnosis yet":H},_=["#9f1853","#491d8b","#003a6d","#8e6a00","#570408"],E=["#a2191f","#eb6200","#f1c21b"],V=["#520408","#8a3800","#8e6a00"],U=[F,"#d0e2ff"],W=["#8d8d8d","#525252",H],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,r.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,r.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,r.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:r,className:n}){return(0,s.jsxs)("button",{type:"button",className:`${L.A.legendToggle} ${t?"":L.A.leftOut} ${n??""}`,"aria-pressed":t,onClick:r,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:r,withShare:n,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":r,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)})}),n&&(0,s.jsxs)("span",{className:L.A.share,children:[w(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:r,figureOf:n,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 r=a[t.label]?e.find(e=>e.label===a[t.label]):e[s-1];return{...t,share:r?w(t.value,r.value):null}}))(a,r).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:n?.(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:r,testId:n}){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":n,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:`${w(c[t],r?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"],er=(0,r.createContext)(null);function en(e,a,t,s={}){let n=(0,r.useContext)(er),i=JSON.stringify([a,s]);(0,r.useEffect)(()=>{n?.(e,a,t,s)},[n,e,i,t]),(0,r.useEffect)(()=>()=>n?.(e,[],!1,{}),[n,e])}let ei=(e,a,t,s)=>t.map(({label:t,value:r,name:n})=>({section:e,group:a,label:n??t,count:r,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:n}=(0,c.useConfig)(),u=(0,h.fU)(),m=(0,g.V)(n.cardiac),p=(0,g.V)(n.primaryCare),f=(0,r.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"},A=(0,ep.D)(C),N=(0,eh.cO)(A.points),w=N.length>=eh.kK?A.median:null,D=(0,r.useMemo)(()=>(0,eh.Se)(A.points,w),[A.points,w]),S=(0,em.I)(em.ml),T=(0,em.B)(t,em.ml),R=N[N.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||A.isLoading?(0,s.jsx)(l.SkeletonText,{paragraph:!0,lineCount:5}):A.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 A.mutate(),children:t("tryAgain","Try again")})]}):N.length<eh.UB?(0,s.jsx)(ec.X,{points:A.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!==w&&(0,s.jsx)("p",{className:ef.A.cardNote,children:t("runChartMedianValue","Median {{value}}",{value:w})}),(0,s.jsx)(eu.c,{name:`${T}, ${j}`,points:A.points,median:w,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 eA({figure:e,scope:a,asOf:t,clinicNames:n,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,r.useMemo)(()=>({endDate:t,...a,...R(e)}),[t,a,e]),{counted:y,countParams:C,pending:A}=Y(j),w=(0,b.y)(y?(g=e.figure,({registrants:f.registrantPatientsReport,waitlist:f.waitlistPatientsReport,cascade:f.cascadePatientsReport,optimisation:f.optimisationPatientsReport})[g]):null,C),{rows:D}=w,{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?e("notDone","Not done"):void 0].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",H=D.length,$={patient:p("patientsCount","{{count}} patients",{count:H}),consultation:p("consultationsCount","{{count}} consultations",{count:H}),recommendation:p("recommendationsCount","{{count}} recommendations",{count:H})},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"):""]:[]],V=(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:$[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(P(e)))!==JSON.stringify(R(P(k(e))))&&V("figure",[O.section,O.label].filter(Boolean).join(": "),()=>d(k(e))),a.cardiacClinic&&V("cardiac",`${p("cardiacClinic","Cardiac clinic")}: ${n.cardiac??""}`,()=>{let{cardiacClinic:e,...t}=a;u(t)}),a.primaryCareClinic&&V("primaryCare",`${p("primaryCareClinic","Primary care clinic")}: ${n.primaryCare??""}`,()=>{let{primaryCareClinic:e,...t}=a;u(t)}),t!==v&&V("asOf",p("asOfDate","As of {{date}}",{date:i()(t).format("DD/MM/YYYY"),interpolation:{escapeValue:!1}}),()=>m(v))]}),!w.error&&!w.isLoading&&!A&&(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})})]}),w.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")}):w.isLoading||A?(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 ew({counts:e,testId:a,figureOf:t,withShares:r,coloured:n}){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=n&&B[e.label]||F;return(0,s.jsxs)("div",{className:r?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)?w(e.value,u):0}%`,backgroundColor:o}})}),(0,s.jsx)("span",{className:L.A.count,children:(0,s.jsx)(q,{value:r?e.value.toLocaleString():e.value,figure:t?.(e.label)})}),r&&(0,s.jsxs)("span",{className:L.A.share,children:[m[i],"%"]})]},e.label)})})}function eD({name:e,counts:a,testId:t,figureOf:r}){let{t:n}=(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:n("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:r?.(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)?w(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:r,clinic:n,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,r.error?(0,s.jsx)(eT,{name:a,retry:r.retry}):r.isLoading?(0,s.jsx)(l.SkeletonText,{paragraph:!0,lineCount:5}):r.isEmpty?(0,s.jsxs)("div",{className:L.A.state,children:[(0,s.jsx)("p",{className:L.A.empty,children:h??(n?x("nobodyAtClinicToCount","Nobody at {{clinic}} to count",{clinic:n}):x("noPatientsToCount","No patients to count"))}),n&&(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:r,error:n,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:r?(0,s.jsx)(l.SkeletonText,{heading:!0,width:"3rem"}):n||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}),!r&&(0,s.jsx)("span",{className:L.A.tileNote,children:n?c("couldNotLoad","could not load"):null===a?c("notReported","not reported"):t})]})]})}function eO({container:e,showScreening:a}){let{t}=(0,o.useTranslation)(),r=(0,el.U)(),n=[["keyFigures",t("overview","Overview")],["active",r.active],["waitlist",r.waitlist],["optimisation",r.optimisation],...a?[["screening",t("screening","Screening")]]:[],["runCharts",r.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}),n.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),n=(0,g.V)(a.primaryCare);return(0,r.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(n,e.primaryCareClinic)}},[s,n,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],eH="1900-01-01",e$=["retainedInCare","echocardiogram","interventionAssigned","interventions","warfarin"],eB="interventions";function e_({measures:e,name:a,testId:t,unit:r="patients"}){let{t:n}=(0,o.useTranslation)(),i="recommendations"===r;return(0,s.jsx)(et,{name:a,segments:[{label:n("done","Done"),colour:U["0"]},{label:i?n("stillWaiting","Still waiting"):n("notDone","Not done"),colour:U["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:[w(e.done,e.done+e.notDone),"%"]}),(0,s.jsx)("span",{className:L.A.doneNotDone,children:i?(0,s.jsx)(o.Trans,{t:n,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:n,i18nKey:"doneNotDoneOf",defaults:"<done>{{done}}</done> done, <notDone>{{notDone}}</notDone> not done, of {{total}}",values:a,components:t})})]})}}),whole:!0,testId:t})}function eE({scope:e,asOf:a,onShowAll:t}){var n;let m,{t:h}=(0,o.useTranslation)(),{careCascade:g,dashboard:p}=(0,c.useConfig)(),f=(0,r.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),R=function(){let[e,a]=(0,r.useState)(()=>{try{let e=JSON.parse(window.localStorage.getItem(eS)??"[]");return Array.isArray(e)?e:[]}catch{return[]}}),t=(0,r.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)),P=(0,r.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)),H=a<i()().format("YYYY-MM-DD"),{cascade:$,leftOutToday:B}=(0,r.useMemo)(()=>{let e=(0,u.o)(F.rows,g.steps),a=H?e.filter(({step:e})=>!eF.includes(e)):e;return{cascade:a,leftOutToday:a.length<e.length}},[F.rows,g.steps,H]),_=(...e)=>$.find(({step:a})=>e.includes(a))?.label,U=_(...eL),K=_("Initiated","Initiated BPG"),J=k((0,b.y)(D?p.waitlistReport:null,S)),G=(0,r.useMemo)(()=>{var e;let a,t,s,r,n,i,o;return e=J.rows,a=e=>String(e??"").trim()||A,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),r=a=>Number(e.find(e=>"performed"===e.breakdown&&e.procedure===a)?.recommendations??0),n=[...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=n.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:r("Mitral balloon valvuloplasty"),surgery:r("Surgery")}}},[J.rows]),Q=(n=G.urgencies,m=e=>E[parseInt(e,10)-1],{...z(n.filter(e=>!m(e)),W),...Object.fromEntries(n.filter(m).map(e=>{let a;return[e,(a=parseInt(e,10),(n.some(t=>t!==e&&parseInt(t,10)===a)&&!/^\d+:/.test(e)?V:E)[a-1])]}))}),X="phone"===(0,c.useLayoutType)(),[Z,es]=(0,r.useState)(X),er=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=er.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)=>(e$.indexOf(e.measure)+1||99)-(e$.indexOf(a.measure)+1||99)),eu=ed.filter(e=>e.measure===eB),em=!!J.error&&!er.error&&eu.length>0,eh=ed.filter(e=>!M.includes(e.measure)),eg={"Confirmatory Diagnosis":h("screenedPositive","Screened positive"),Diagnosed:h("hadConfirmatoryEcho","Had a confirmatory echo"),"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},eA=eC("Active"),eN=eC("Prescribed","Prescribed Prophylaxis"),eO={clinic:v,onShowAll:t},eH=F.rows.find(e=>["Prescribed","Prescribed Prophylaxis"].includes(String(e.step))),eV=e=>a=>({figure:"registrants",breakdown:e,label:a}),eU=h("keyFigures","Key figures"),eW=(e,a)=>e.error?[]:a(),ez=h("proceduralWaitlist","Procedural waitlist"),eG=h("activeRegistrants","Active registrants"),eq=h("medicalOptimisationDescription","Of the {{count}} active registrants, unless a row says otherwise",{count:P.active}),eQ=(e,t,s=h("notDone","Not done"))=>t.flatMap(t=>ei(e,t.label,null===t.notDone?[{label:"",value:t.done}]:[{label:h("done","Done"),value:t.done},{label:s,value:t.notDone}],a));return en("figures",[...eW(O,()=>ei(eU,"",[{label:h("registered","Registered"),value:P.registered},{label:h("active","Active"),value:P.active}],a)),...eW(F,()=>null===eN?[]:ei(eU,"",[{label:h("onSecondaryProphylaxis","On secondary prophylaxis"),value:eN}],a)),...eW(J,()=>ei(eU,"",[{label:h("waitingForAProcedure","Waiting for a procedure"),value:G.patients},{label:h("openRecommendationsFigure","Open recommendations"),value:G.total}],a)),...eW(O,()=>ei(h("registrantStatus","Registrant status"),"",P.status,a)),...eW(F,()=>ei(h("rhdCareCascade","RHD care cascade"),"",$.map(({label:e,value:a})=>({label:h(e),value:a})),a)),...eW(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)]),...eW(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))]),...eW(er,()=>eQ(ez,eu,h("stillWaiting","Still waiting"))),...eW(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)]),...eW(er,()=>eQ(h("medicalOptimisation","Medical optimisation"),eh)),...!p.showScreening||el.error||ec.error?[]:[...ei(h("screeningCascade","Screening cascade"),h("cascade","Cascade"),ep,a),...ei(h("screeningCascade","Screening cascade"),h("diagnosesAfterTheEcho","Diagnoses after the echo"),ev,a),...ei(h("screeningCascade","Screening cascade"),h("rhdDetails","RHD details"),ej,a)]],[O,F,J,er].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:P.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:P.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:eN,note:null===eA?h("activeRhdNotReported","active RHD not reported"):h("shareOfActiveRhd","{{share}}% of active RHD",{share:w(eN??0,eA)}),isLoading:F.isLoading,error:F.error,figure:eH&&{figure:"cascade",step:String(eH.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:P.registered}),state:eM(O,!P.registered),collapse:R("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:eV("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:eM(F,eI($)),collapse:R("cascade"),exportId:"cascade",...eO,children:(0,s.jsx)(ea,{name:h("rhdCareCascade","RHD care cascade"),steps:$,shareOf:U&&K?{[U]:K}:void 0,testId:"dashboard-cascade-step",figureOf:e=>({figure:"cascade",step:$.find(a=>a.label===e)?.step})})}),(0,s.jsx)(eR,{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: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:P.sex,centre:h("activeCentre","active"),testId:"dashboard-sex",withShare:!0,figureOf:eV("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:eV("age")})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:L.A.subheading,children:h("disease","Disease")}),(0,s.jsx)(ew,{counts:P.category,testId:"dashboard-category",figureOf:eV("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:P.active}),name:h("proceduralWaitlist","Procedural waitlist"),description:h("waitlistDescription","Open recommendations in each active patient's latest consultation, by urgency"),state:em?eM(er,!1):eM(J,!G.total&&!G.performed.bmv&&!G.performed.surgery&&!er.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):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"}),er.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)(eR,{title:h("medicalOptimisation","Medical optimisation"),description:eq,state:eM(er,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("rhdScreening","RHD screening")}),(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 what their confirmatory echo showed"),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("diagnosesAfterTheEcho","Diagnoses after the echo")}),(0,s.jsx)(ee,{name:h("diagnosesAfterTheEcho","Diagnoses after the echo"),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)(ew,{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 eV=["Yes","No","Not recorded"],eU=["Children 0-9","Adolescents 10-19","Adults 20+","Age unknown"],eW=["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:n}){let{t:d}=(0,o.useTranslation)(),{dashboard:u}=(0,c.useConfig)(),[m,h]=(0,r.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,r.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),A=Number(y.find(e=>"female"===e.breakdown)?.patients??0),N=e=>a=>{let t=a&&i()(a).format("YYYY-MM-DD");t&&t>=eH&&h(a=>({...a,[e]:t}))},D=d("screeningFromRegistrations","Screening, from registrations"),S=d("periodRange","{{start}} to {{end}}",{start:p,end:g});return en("registrations",j.error?[]:[...ei(D,"",[{label:d("registered","Registered"),value:C},{label:d("female","Female"),value:A}],S),...ei(D,d("screenPlus","Screen +"),ez(y,"screen",eV),S),...ei(D,d("ageAtRegistration","Age at registration"),ez(y,"age",eU),S),...ei(D,d("caseDetectedBy","Case detected by"),ez(y,"detected",eW),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:{...eM(j,!C),isLoading:j.isLoading||v},clinic:t,onShowAll:n,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()(eH).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:[w(A,C),"%"]})]})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:L.A.subheading,children:d("screenPlus","Screen +")}),(0,s.jsx)(ew,{counts:ez(y,"screen",eV),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)(ew,{counts:ez(y,"age",eU),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",eW),centre:d("registeredCentre","registered"),testId:"dashboard-detected"})]})]})})}function eJ({scope:e,clinic:a,onShowAll:t}){let{t:n}=(0,o.useTranslation)(),c=(0,r.useMemo)(()=>(0,eN.$9)(eN.t3),[]),{settingLabel:d,metricLabel:u}=(0,eN.NH)(),[m,g]=(0,r.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,r.useMemo)(()=>j?{clinics:Object.values(e),startMonth:x,endMonth:p}:null,[j,e,x,p]),{summary:A,error:N,isLoading:D,mutate:S}=(0,eN.Y9)(C),T=A?.screened??0,R=(e,a,t,r,n)=>(0,s.jsx)(l.Select,{id:e,labelText:a,value:t,onChange:e=>g(a=>({...a,[r]:e.target.value})),children:n.map(e=>(0,s.jsx)(l.SelectItem,{value:e,text:(0,eN.g6)(e)},e))}),k=n("clinicsAddedTogether","{{clinics}} added together",{clinics:a}),O=(Object.keys(e).length>1?k:a)??("ready"===v.status?v.names.join(", ")||n("yourClinics","your clinics"):n("everyClinic","every clinic")),P=n("rhdScreening","RHD screening"),M=n("periodRange","{{start}} to {{end}}",{start:x,end:p});return en("rhdScreening",N||!A?[]:[...ei(P,"",[{label:u.screened,value:T},{label:u.females,value:A.females??0},{label:u.positive,value:A.positive??0}],M),...ei(P,n("result","Result"),[{label:n("negative","Negative"),value:A.negative??0},{label:u.positive,value:A.positive??0}],M),...ei(P,n("age","Age"),[{label:u.children,value:A.children??0},{label:u.adolescents,value:A.adolescents??0},{label:u.adults,value:A.adults??0}],M),...ei(P,n("setting","Setting"),eN.W0.map(e=>({label:d[e],value:A.settings?.[e]??0})),M)],D||y,{screeningFromMonth:x,screeningToMonth:p}),(0,s.jsxs)(eR,{title:n("rhdScreening","RHD screening"),description:n("rhdScreeningDescription","Monthly counts, {{clinic}}, {{start}} to {{end}}",{clinic:O,start:(0,eN.g6)(x),end:(0,eN.g6)(p)}),state:{isLoading:D||y,error:N,retry:()=>void S(),isEmpty:!A?.months},clinic:a,onShowAll:t,embedded:!0,exportId:"rhdScreening",emptyText:a?n("noScreeningCountsAt","No screening counts entered for {{clinic}} in the period",{clinic:a}):n("noScreeningCounts","No screening counts entered in the period"),wide:!0,controls:(0,s.jsxs)("div",{className:L.A.filters,children:[R("dashboard-screening-from",n("fromMonth","From"),x,"start",c.filter(e=>e<=p)),R("dashboard-screening-to",n("toMonth","To"),p,"end",c)]}),children:[(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:[w(A?.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:(A?.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:n("result","Result")}),(0,s.jsx)(ew,{withShares:!0,counts:[{label:n("negative","Negative"),value:A?.negative??0},{label:u.positive,value:A?.positive??0}],testId:"dashboard-screening-result"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:L.A.subheading,children:n("age","Age")}),(0,s.jsx)(ew,{withShares:!0,counts:[{label:u.children,value:A?.children??0},{label:u.adolescents,value:A?.adolescents??0},{label:u.adults,value:A?.adults??0}],testId:"dashboard-screening-age"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:L.A.subheading,children:n("setting","Setting")}),(0,s.jsx)(ew,{withShares:!0,counts:eN.W0.map(e=>({label:d[e],value:A?.settings?.[e]??0})),testId:"dashboard-screening-setting"})]})]}),(0,s.jsx)("p",{className:L.A.note,children:n("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,n,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=>n({asOf:e===u?"":e}),v=(0,r.useMemo)(()=>d?void 0:Object.fromEntries(Object.entries({cardiacClinic:t.cardiacClinic,primaryCareClinic:t.primaryCareClinic}).filter(([,e])=>e)),[d,t.cardiacClinic,t.primaryCareClinic]),j=(0,r.useCallback)(e=>n({cardiacClinic:e.cardiacClinic??"",primaryCareClinic:e.primaryCareClinic??""}),[n]),y=(0,r.useMemo)(()=>S.includes(t.figure)?Object.fromEntries(T.map(e=>[e,t[e]])):null,[t]),C="ready"===a.status?Object.keys(a.params):[],A=e=>(0,x.j)(eG,{...t,...e},C),N=e=>{window.history.pushState(window.history.state,"",A(e)),n(e)},w=eP(v??{}),[D,R]=(0,r.useState)({}),k=(0,r.useCallback)((e,a,t,s)=>R(r=>({...r,[e]:{rows:a,isLoading:t,filters:s}})),[]),P=es.flatMap(e=>D[e]?.rows??[]),M=(0,r.useRef)(null),I=(0,c.useSession)(),{dashboard:Y}=(0,c.useConfig)(),F=Y.showScreening,H=(0,h.fU)(),$=[w.cardiac,w.primaryCare].filter(Boolean).join(", ")||("ready"===H.status?H.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:[$," \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)(eA,{figure:y,scope:v,asOf:g,clinicNames:w,onFigure:e=>n({...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()(eH).toDate(),maxDate:new Date,onChange:e=>{let a=e&&i()(e).format("YYYY-MM-DD");a&&a>=eH&&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:$,asOf:g,showScreening:F})]})]}),(0,s.jsx)(O.Provider,{value:{href:e=>A({...eq,...e}),open:e=>N({...eq,...e})},children:(0,s.jsx)(er.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 r=t(6144),n=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)(r.ConfigurableLink,{to:a??(0,n.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),r=t.n(s),n=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)=>r()().subtract(a,"month").format("YYYY-MM")),p=e=>r()(`${e}-01`).format("MMMM YYYY");function f(){let{t:e}=(0,n.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:r,isLoading:n,mutate:i}=o()(t,async e=>(await (0,l.openmrsFetch)(e)).data,{revalidateOnFocus:!1,revalidateOnReconnect:!1});return{month:s,error:r,isLoading:n,mutate:i}}async function v(e,a,t,s,r){let n=b(e,a),{data:i}=await (0,l.openmrsFetch)(n,{method:"POST",headers:{"Content-Type":"application/json"},body:{counts:t,notes:s}});await r(n,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:r,mutate:n}=o()(a,async e=>(await (0,l.openmrsFetch)(e)).data,{shouldRetryOnError:!1});return{summary:t,error:s,isLoading:r,mutate:n}}},5802(e,a,t){t.d(a,{F:()=>p});var s=t(7858),r=t(4335),n=t(8406),i=t.n(n),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:n={},headers:f,rows:b,disabled:x,size:v="sm"}){let{t:j}=(0,o.useTranslation)(),[y,C]=(0,r.useState)(!1),A=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:n}),(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:A,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),r=t(6144),n=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,r.usePagination)(e,t),u=(0,n.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:()=>n});var s=t(1943),r=t(6144);function n(){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,r.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),r=t(4335),i=t(8406),n=t.n(i),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 w(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 C="Not given",N=(e,a)=>a===C?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),r=100-s.reduce((e,a)=>e+a,0),i=t.map((e,a)=>({index:a,remainder:e-s[a]}));return i.sort((e,a)=>a.remainder-e.remainder||e.index-a.index),i.slice(0,r).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,r.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,r.useMemo)(()=>t?.length?{...e,clinics:t.join(",")}:e,[e,t]),pending:"pending"===a.status}}var L=t(1327);let F="#009d9a",H="#c6c6c6",$="#007d79",B={Active:F,"Lost to follow-up":"#da1e28","Voluntary inactivity":"#ba4e00","Physical relocation":"#6f6f6f",Deceased:"#161616","Rheumatic Heart Disease/Rheumatic Fever":$,"Acute rheumatic fever":"#08bdba","RHD A":F,"RHD B":$,"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":H,"No status recorded":H,"No diagnosis yet":H},_=["#9f1853","#491d8b","#003a6d","#8e6a00","#570408"],W=["#a2191f","#eb6200","#f1c21b"],V=["#520408","#8a3800","#8e6a00"],E=[F,"#d0e2ff"],U=["#8d8d8d","#525252",H],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,r.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,r.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,r.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:r,className:i}){return(0,s.jsxs)("button",{type:"button",className:`${L.A.legendToggle} ${t?"":L.A.leftOut} ${i??""}`,"aria-pressed":t,onClick:r,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:r,withShare:i,figureOf:n}){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":r,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:n?.(e.label)})}),i&&(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:r,figureOf:i,height:n="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,n),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 r=a[t.label]?e.find(e=>e.label===a[t.label]):e[s-1];return{...t,share:r?A(t.value,r.value):null}}))(a,r).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:i?.(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:r,testId:i}){let{isShown:n,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+(n(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:n(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":i,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],r?l[t]:d)}%`},children:e.values.map((e,t)=>e&&n(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"],er=(0,r.createContext)(null);function ei(e,a,t,s={}){let i=(0,r.useContext)(er),n=JSON.stringify([a,s]);(0,r.useEffect)(()=>{i?.(e,a,t,s)},[i,e,n,t]),(0,r.useEffect)(()=>()=>i?.(e,[],!1,{}),[i,e])}let en=(e,a,t,s)=>t.map(({label:t,value:r,name:i})=>({section:e,group:a,label:i??t,count:r,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:i}=(0,c.useConfig)(),u=(0,h.fU)(),m=(0,g.V)(i.cardiac),p=(0,g.V)(i.primaryCare),f=(0,r.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,w=y?null:{metric:em.ml,clinic:v||null,startDate:n()().subtract(12,"month").format("YYYY-MM-DD"),endDate:n()().format("YYYY-MM-DD"),points:"week"},C=(0,ep.D)(w),N=(0,eh.cO)(C.points),A=N.length>=eh.kK?C.median:null,D=(0,r.useMemo)(()=>(0,eh.Se)(C.points,A),[C.points,A]),S=(0,em.I)(em.ml),T=(0,em.B)(t,em.ml),R=N[N.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||C.isLoading?(0,s.jsx)(l.SkeletonText,{paragraph:!0,lineCount:5}):C.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 C.mutate(),children:t("tryAgain","Try again")})]}):N.length<eh.UB?(0,s.jsx)(ec.X,{points:C.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!==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:C.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?${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),ew=t(3361);function eC({figure:e,scope:a,asOf:t,clinicNames:i,onFigure:d,onScope:u,onAsOf:m,onBack:h}){let g,{t:p}=(0,o.useTranslation)(),{dashboard:f,careCascade:x}=(0,c.useConfig)(),v=n()().format("YYYY-MM-DD"),j=(0,r.useMemo)(()=>({endDate:t,...a,...R(e)}),[t,a,e]),{counted:y,countParams:w,pending:C}=Y(j),A=(0,b.y)(y?(g=e.figure,({registrants:f.registrantPatientsReport,waitlist:f.waitlistPatientsReport,cascade:f.cascadePatientsReport,optimisation:f.optimisationPatientsReport})[g]):null,w),{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",H=D.length,$={patient:p("patientsCount","{{count}} patients",{count:H}),consultation:p("consultationsCount","{{count}} consultations",{count:H}),recommendation:p("recommendationsCount","{{count}} recommendations",{count:H})},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")]:[]],W=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?n()(String(e.figure_date)).format("DD/MM/YYYY"):""]:[]],V=(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:$[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(P(e)))!==JSON.stringify(R(P(k(e))))&&V("figure",[O.section,O.label].filter(Boolean).join(": "),()=>d(k(e))),a.cardiacClinic&&V("cardiac",`${p("cardiacClinic","Cardiac clinic")}: ${i.cardiac??""}`,()=>{let{cardiacClinic:e,...t}=a;u(t)}),a.primaryCareClinic&&V("primaryCare",`${p("primaryCareClinic","Primary care clinic")}: ${i.primaryCare??""}`,()=>{let{primaryCareClinic:e,...t}=a;u(t)}),t!==v&&V("asOf",p("asOfDate","As of {{date}}",{date:n()(t).format("DD/MM/YYYY"),interpolation:{escapeValue:!1}}),()=>m(v))]}),!A.error&&!A.isLoading&&!C&&(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:w,headers:_,rows:()=>D.map(W),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||C?(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:W(e).slice(1).map((a,t)=>(0,s.jsx)(l.TableCell,{children:0===t?(0,s.jsx)(ew.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:r,coloured:i}){let{t:n}=(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:n("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,n)=>{let o=i&&B[e.label]||F;return(0,s.jsxs)("div",{className:r?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:r?e.value.toLocaleString():e.value,figure:t?.(e.label)})}),r&&(0,s.jsxs)("span",{className:L.A.share,children:[m[n],"%"]})]},e.label)})})}function eD({name:e,counts:a,testId:t,figureOf:r}){let{t:i}=(0,o.useTranslation)(),n=K(),{isShown:l,toggle:c}=Q(a.map(e=>e.label));if(!a.length)return(0,s.jsx)("p",{className:L.A.empty,children:i("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:r?.(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:n(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:r,clinic:i,onShowAll:n,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,r.error?(0,s.jsx)(eT,{name:a,retry:r.retry}):r.isLoading?(0,s.jsx)(l.SkeletonText,{paragraph:!0,lineCount:5}):r.isEmpty?(0,s.jsxs)("div",{className:L.A.state,children:[(0,s.jsx)("p",{className:L.A.empty,children:h??(i?x("nobodyAtClinicToCount","Nobody at {{clinic}} to count",{clinic:i}):x("noPatientsToCount","No patients to count"))}),i&&(0,s.jsx)(l.Button,{kind:"tertiary",size:"md",onClick:n,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:r,error:i,figure:n}){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:r?(0,s.jsx)(l.SkeletonText,{heading:!0,width:"3rem"}):i||null===a?"–":(0,s.jsx)(q,{value:a,figure:n})}),(0,s.jsxs)("span",{className:L.A.figureText,children:[(0,s.jsx)("span",{className:L.A.figureLabel,children:e}),!r&&(0,s.jsx)("span",{className:L.A.tileNote,children:i?c("couldNotLoad","could not load"):null===a?c("notReported","not reported"):t})]})]})}function eO({container:e,showScreening:a}){let{t}=(0,o.useTranslation)(),r=(0,el.U)(),i=[["keyFigures",t("overview","Overview")],["active",r.active],["waitlist",r.waitlist],["optimisation",r.optimisation],...a?[["screening",t("screening","Screening")]]:[],["runCharts",r.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}),i.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),i=(0,g.V)(a.primaryCare);return(0,r.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(i,e.primaryCareClinic)}},[s,i,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],eH="1900-01-01",e$=["retainedInCare","echocardiogram","interventionAssigned","interventions","warfarin"],eB="interventions";function e_({measures:e,name:a,testId:t,unit:r="patients"}){let{t:i}=(0,o.useTranslation)(),n="recommendations"===r;return(0,s.jsx)(et,{name:a,segments:[{label:n?i("done","Done"):i("yes","Yes"),colour:E["0"]},{label:n?i("stillWaiting","Still waiting"):i("no","No"),colour:E["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:n?(0,s.jsx)(o.Trans,{t:i,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:i,i18nKey:"yesNoOf",defaults:"<done>{{done}}</done> yes, <notDone>{{notDone}}</notDone> no, of {{total}}",values:a,components:t})})]})}}),whole:!0,testId:t})}function eW({scope:e,asOf:a,onShowAll:t}){var i;let m,{t:h}=(0,o.useTranslation)(),{careCascade:g,dashboard:p}=(0,c.useConfig)(),f=(0,r.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),R=function(){let[e,a]=(0,r.useState)(()=>{try{let e=JSON.parse(window.localStorage.getItem(eS)??"[]");return Array.isArray(e)?e:[]}catch{return[]}}),t=(0,r.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)),P=(0,r.useMemo)(()=>{var e;let a,t;return a=w(e=O.rows,"status"),t=w(e,"age"),{status:a,sex:w(e,"sex"),age:[...t].sort((e,a)=>(j.indexOf(e.label)+1||99)-(j.indexOf(a.label)+1||99)),category:w(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)),H=a<n()().format("YYYY-MM-DD"),{cascade:$,leftOutToday:B}=(0,r.useMemo)(()=>{let e=(0,u.o)(F.rows,g.steps),a=H?e.filter(({step:e})=>!eF.includes(e)):e;return{cascade:a,leftOutToday:a.length<e.length}},[F.rows,g.steps,H]),_=(...e)=>$.find(({step:a})=>e.includes(a))?.label,E=_(...eL),K=_("Initiated","Initiated BPG"),J=k((0,b.y)(D?p.waitlistReport:null,S)),G=(0,r.useMemo)(()=>{var e;let a,t,s,r,i,n,o;return e=J.rows,a=e=>String(e??"").trim()||C,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),r=a=>Number(e.find(e=>"performed"===e.breakdown&&e.procedure===a)?.recommendations??0),i=[...new Set(t.map(e=>String(e.procedure)))].sort(),n=[...new Set(t.map(e=>String(e.urgency)))].sort((e,a)=>e.localeCompare(a,void 0,{numeric:!0})),o=i.map(e=>({procedure:e,counts:n.map(a=>t.filter(t=>t.procedure===e&&t.urgency===a).reduce((e,a)=>e+a.recommendations,0))})),{urgencies:n,rows:o,total:Number(s?.recommendations??0),patients:Number(s?.patients??0),performed:{bmv:r("Mitral balloon valvuloplasty"),surgery:r("Surgery")}}},[J.rows]),Q=(i=G.urgencies,m=e=>W[parseInt(e,10)-1],{...z(i.filter(e=>!m(e)),U),...Object.fromEntries(i.filter(m).map(e=>{let a;return[e,(a=parseInt(e,10),(i.some(t=>t!==e&&parseInt(t,10)===a)&&!/^\d+:/.test(e)?V:W)[a-1])]}))}),X="phone"===(0,c.useLayoutType)(),[Z,es]=(0,r.useState)(X),er=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=er.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)=>(e$.indexOf(e.measure)+1||99)-(e$.indexOf(a.measure)+1||99)),eu=ed.filter(e=>e.measure===eB),em=!!J.error&&!er.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),ew=(...e)=>{let a=F.rows.find(a=>e.includes(String(a.step)));return a?Number(a.patients??0):null},eC=ew("Active"),eN=ew("Prescribed","Prescribed Prophylaxis"),eO={clinic:v,onShowAll:t},eH=F.rows.find(e=>["Prescribed","Prescribed Prophylaxis"].includes(String(e.step))),eV=e=>a=>({figure:"registrants",breakdown:e,label:a}),eE=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,r])=>t.flatMap(t=>en(e,t.label,null===t.notDone?[{label:"",value:t.done}]:[{label:s,value:t.done},{label:r,value:t.notDone}],a));return ei("figures",[...eU(O,()=>en(eE,"",[{label:h("registered","Registered"),value:P.registered},{label:h("active","Active"),value:P.active}],a)),...eU(F,()=>null===eN?[]:en(eE,"",[{label:h("onSecondaryProphylaxis","On secondary prophylaxis"),value:eN}],a)),...eU(J,()=>en(eE,"",[{label:h("waitingForAProcedure","Waiting for a procedure"),value:G.patients},{label:h("openRecommendationsFigure","Open recommendations"),value:G.total}],a)),...eU(O,()=>en(h("registrantStatus","Registrant status"),"",P.status,a)),...eU(F,()=>en(h("rhdCareCascade","RHD care cascade"),"",$.map(({label:e,value:a})=>({label:h(e),value:a})),a)),...eU(O,()=>[...en(eG,h("sex","Sex"),P.sex,a),...en(eG,h("age","Age"),P.age,a),...en(eG,h("disease","Disease"),P.category,a)]),...eU(J,()=>[...G.rows.flatMap(e=>en(ez,N(h,e.procedure),e.counts.map((e,a)=>({label:N(h,G.urgencies[a]),value:e})),a))]),...eU(er,()=>eQ(ez,eu,[h("done","Done"),h("stillWaiting","Still waiting")])),...eU(J,()=>[...en(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(er,()=>eQ(h("medicalOptimisation","Medical optimisation"),eh,[h("yes","Yes"),h("no","No")])),...!p.showScreening||el.error||ec.error?[]:[...en(h("screeningCascade","Screening cascade"),h("cascade","Cascade"),ep,a),...en(h("screeningCascade","Screening cascade"),h("whatTheDiagnosisFound","What the diagnosis found"),ev,a),...en(h("screeningCascade","Screening cascade"),h("rhdDetails","RHD details"),ej,a)]],[O,F,J,er].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:P.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:P.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:eN,note:null===eC?h("activeRhdNotReported","active RHD not reported"):h("shareOfActiveRhd","{{share}}% of active RHD",{share:A(eN??0,eC)}),isLoading:F.isLoading,error:F.error,figure:eH&&{figure:"cascade",step:String(eH.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:P.registered}),state:eM(O,!P.registered),collapse:R("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:eV("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:eM(F,eI($)),collapse:R("cascade"),exportId:"cascade",...eO,children:(0,s.jsx)(ea,{name:h("rhdCareCascade","RHD care cascade"),steps:$,shareOf:E&&K?{[E]:K}:void 0,testId:"dashboard-cascade-step",figureOf:e=>({figure:"cascade",step:$.find(a=>a.label===e)?.step})})}),(0,s.jsx)(eR,{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: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:P.sex,centre:h("activeCentre","active"),testId:"dashboard-sex",withShare:!0,figureOf:eV("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:eV("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:eV("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:P.active}),name:h("proceduralWaitlist","Procedural waitlist"),description:h("waitlistDescription","Open recommendations in each active patient's latest consultation, by urgency"),state:em?eM(er,!1):eM(J,!G.total&&!G.performed.bmv&&!G.performed.surgery&&!er.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):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"}),er.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)(eR,{title:h("medicalOptimisation","Medical optimisation"),description:eq,state:eM(er,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("rhdScreening","RHD screening")}),(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: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 eV=["Yes","No","Not recorded"],eE=["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:i}){let{t:d}=(0,o.useTranslation)(),{dashboard:u}=(0,c.useConfig)(),[m,h]=(0,r.useState)({}),g=m.end??a,p=m.start&&m.start<=g?m.start:n()(g).subtract(364,"day").format("YYYY-MM-DD"),{counted:f,countParams:x,pending:v}=Y((0,r.useMemo)(()=>({startDate:p,endDate:g,...e}),[p,g,e])),j=(0,b.y)(f?u.screeningReport:null,x),{rows:y}=j,w=Number(y.find(e=>"total"===e.breakdown)?.patients??0),C=Number(y.find(e=>"female"===e.breakdown)?.patients??0),N=e=>a=>{let t=a&&n()(a).format("YYYY-MM-DD");t&&t>=eH&&h(a=>({...a,[e]:t}))},D=d("screeningFromRegistrations","Screening, from registrations"),S=d("periodRange","{{start}} to {{end}}",{start:p,end:g});return ei("registrations",j.error?[]:[...en(D,"",[{label:d("registered","Registered"),value:w},{label:d("female","Female"),value:C}],S),...en(D,d("screenPlus","Screen +"),ez(y,"screen",eV),S),...en(D,d("ageAtRegistration","Age at registration"),ez(y,"age",eE),S),...en(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:{...eM(j,!w),isLoading:j.isLoading||v},clinic:t,onShowAll:i,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:n()(p).toDate(),minDate:n()(eH).toDate(),maxDate:n()(g).toDate(),onChange:N("start")}),(0,s.jsx)(c.OpenmrsDatePicker,{id:"dashboard-registered-to",labelText:d("registeredTo","Registered to"),value:n()(g).toDate(),minDate:n()(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:w})]}),(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(C,w),"%"]})]})]}),(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",eV),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",eE),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:i}=(0,o.useTranslation)(),c=(0,r.useMemo)(()=>(0,eN.$9)(eN.t3),[]),{settingLabel:d,metricLabel:u}=(0,eN.NH)(),[m,g]=(0,r.useState)({}),p=m.end??c[1],f=n()(`${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,w=(0,r.useMemo)(()=>j?{clinics:Object.values(e),startMonth:x,endMonth:p}:null,[j,e,x,p]),{summary:C,error:N,isLoading:D,mutate:S}=(0,eN.Y9)(w),T=C?.screened??0,R=(e,a,t,r,i)=>(0,s.jsx)(l.Select,{id:e,labelText:a,value:t,onChange:e=>g(a=>({...a,[r]:e.target.value})),children:i.map(e=>(0,s.jsx)(l.SelectItem,{value:e,text:(0,eN.g6)(e)},e))}),k=i("clinicsAddedTogether","{{clinics}} added together",{clinics:a}),O=(Object.keys(e).length>1?k:a)??("ready"===v.status?v.names.join(", ")||i("yourClinics","your clinics"):i("everyClinic","every clinic")),P=i("rhdScreening","RHD screening"),M=i("periodRange","{{start}} to {{end}}",{start:x,end:p});return ei("rhdScreening",N||!C?[]:[...en(P,"",[{label:u.screened,value:T},{label:u.females,value:C.females??0},{label:u.positive,value:C.positive??0}],M),...en(P,i("result","Result"),[{label:i("negative","Negative"),value:C.negative??0},{label:u.positive,value:C.positive??0}],M),...en(P,i("age","Age"),[{label:u.children,value:C.children??0},{label:u.adolescents,value:C.adolescents??0},{label:u.adults,value:C.adults??0}],M),...en(P,i("setting","Setting"),eN.W0.map(e=>({label:d[e],value:C.settings?.[e]??0})),M)],D||y,{screeningFromMonth:x,screeningToMonth:p}),(0,s.jsxs)(eR,{title:i("rhdScreening","RHD screening"),description:i("rhdScreeningDescription","Monthly counts, {{clinic}}, {{start}} to {{end}}",{clinic:O,start:(0,eN.g6)(x),end:(0,eN.g6)(p)}),state:{isLoading:D||y,error:N,retry:()=>void S(),isEmpty:!C?.months},clinic:a,onShowAll:t,embedded:!0,exportId:"rhdScreening",emptyText:a?i("noScreeningCountsAt","No screening counts entered for {{clinic}} in the period",{clinic:a}):i("noScreeningCounts","No screening counts entered in the period"),wide:!0,controls:(0,s.jsxs)("div",{className:L.A.filters,children:[R("dashboard-screening-from",i("fromMonth","From"),x,"start",c.filter(e=>e<=p)),R("dashboard-screening-to",i("toMonth","To"),p,"end",c)]}),children:[(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(C?.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:(C?.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:i("result","Result")}),(0,s.jsx)(eA,{withShares:!0,counts:[{label:i("negative","Negative"),value:C?.negative??0},{label:u.positive,value:C?.positive??0}],testId:"dashboard-screening-result"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:L.A.subheading,children:i("age","Age")}),(0,s.jsx)(eA,{withShares:!0,counts:[{label:u.children,value:C?.children??0},{label:u.adolescents,value:C?.adolescents??0},{label:u.adults,value:C?.adults??0}],testId:"dashboard-screening-age"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:L.A.subheading,children:i("setting","Setting")}),(0,s.jsx)(eA,{withShares:!0,counts:eN.W0.map(e=>({label:d[e],value:C?.settings?.[e]??0})),testId:"dashboard-screening-setting"})]})]}),(0,s.jsx)("p",{className:L.A.note,children:i("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,i,d]=(0,x.y)(eG,"ready"===a.status?a.params:"error"===a.status?{}:"pending"),u=n()().format("YYYY-MM-DD"),g=t.asOf||u,b=e=>i({asOf:e===u?"":e}),v=(0,r.useMemo)(()=>d?void 0:Object.fromEntries(Object.entries({cardiacClinic:t.cardiacClinic,primaryCareClinic:t.primaryCareClinic}).filter(([,e])=>e)),[d,t.cardiacClinic,t.primaryCareClinic]),j=(0,r.useCallback)(e=>i({cardiacClinic:e.cardiacClinic??"",primaryCareClinic:e.primaryCareClinic??""}),[i]),y=(0,r.useMemo)(()=>S.includes(t.figure)?Object.fromEntries(T.map(e=>[e,t[e]])):null,[t]),w="ready"===a.status?Object.keys(a.params):[],C=e=>(0,x.j)(eG,{...t,...e},w),N=e=>{window.history.pushState(window.history.state,"",C(e)),i(e)},A=eP(v??{}),[D,R]=(0,r.useState)({}),k=(0,r.useCallback)((e,a,t,s)=>R(r=>({...r,[e]:{rows:a,isLoading:t,filters:s}})),[]),P=es.flatMap(e=>D[e]?.rows??[]),M=(0,r.useRef)(null),I=(0,c.useSession)(),{dashboard:Y}=(0,c.useConfig)(),F=Y.showScreening,H=(0,h.fU)(),$=[A.cardiac,A.primaryCare].filter(Boolean).join(", ")||("ready"===H.status?H.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:[$," \xb7"," ",e("figuresAsOfDate","figures as of {{date}}",{date:(0,c.formatDate)(n()(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)(eC,{figure:y,scope:v,asOf:g,clinicNames:A,onFigure:e=>i({...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:n()(g).toDate(),minDate:n()(eH).toDate(),maxDate:new Date,onChange:e=>{let a=e&&n()(e).format("YYYY-MM-DD");a&&a>=eH&&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:$,asOf:g,showScreening:F})]})]}),(0,s.jsx)(O.Provider,{value:{href:e=>C({...eq,...e}),open:e=>N({...eq,...e})},children:(0,s.jsx)(er.Provider,{value:k,children:(0,s.jsx)(eW,{scope:v,asOf:g,onShowAll:()=>j({})})})})]}):(0,s.jsx)(l.SkeletonText,{paragraph:!0,lineCount:6})})]})}},3361(e,a,t){t.d(a,{e:()=>n});var s=t(7858);t(4335);var r=t(6144),i=t(9342);function n({row:e,to:a,detail:t,children:o}){let l=String(e.rhd_id??"");return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(r.ConfigurableLink,{to:a??(0,i.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),r=t.n(s),i=t(1943),n=t(3483),o=t.n(n),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)=>r()().subtract(a,"month").format("YYYY-MM")),p=e=>r()(`${e}-01`).format("MMMM YYYY");function f(){let{t:e}=(0,i.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:r,isLoading:i,mutate:n}=o()(t,async e=>(await (0,l.openmrsFetch)(e)).data,{revalidateOnFocus:!1,revalidateOnReconnect:!1});return{month:s,error:r,isLoading:i,mutate:n}}async function v(e,a,t,s,r){let i=b(e,a),{data:n}=await (0,l.openmrsFetch)(i,{method:"POST",headers:{"Content-Type":"application/json"},body:{counts:t,notes:s}});await r(i,n,{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:r,mutate:i}=o()(a,async e=>(await (0,l.openmrsFetch)(e)).data,{shouldRetryOnError:!1});return{summary:t,error:s,isLoading:r,mutate:i}}},5802(e,a,t){t.d(a,{F:()=>p});var s=t(7858),r=t(4335),i=t(8406),n=t.n(i),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:i={},headers:f,rows:b,disabled:x,size:v="sm"}){let{t:j}=(0,o.useTranslation)(),[y,w]=(0,r.useState)(!1),C=async()=>{let s;w(!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)}),w(!1);return}try{await (0,m.kt)({list:a,columns:f,rows:s.length,identifiers:t,filters:i}),(0,g.t)(`${e}-${n()().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{w(!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:C,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),r=t(6144),i=t(4623);let n=[10,25,50,100];function o(e,a){let[t,o]=(0,s.useState)(n[0]),{results:l,currentPage:c,goTo:d}=(0,r.usePagination)(e,t),u=(0,i.T)();return(0,s.useEffect)(()=>d(1),[a,d]),{results:l,paginationProps:{...u,page:c,pageSize:t,pageSizes:n,totalItems:e.length,onChange:({page:e,pageSize:a})=>{o(a),d(e)}}}}},4623(e,a,t){t.d(a,{T:()=>i});var s=t(1943),r=t(6144);function i(){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,r.getCoreTranslation)("paginationOfPages","of {{count}} pages",{count:a})}}}}]);
|