TMT91/prostate-pulse-analytics-portal
0
1 2document.addEventListener('DOMContentLoaded', function() {3 // Initialize charts4 const tableData = [5 {hospitalNumber:'6268627057',age:66,ethnicity:'Indian',familyHistory:'Not discussed',selfReferral:'No',symptomatic:'Asymptomatic/ Requested with arthritis inx',DRE:'',adviceGiven:'',result:'Normal',resultNumber:0.9,action:'No further action',outcome:'',cancerDiagnosis:''},6 {hospitalNumber:'4162442959',age:55,ethnicity:'British',familyHistory:'Not discussed',selfReferral:'No',symptomatic:'Symp Erectile dysf',DRE:'',adviceGiven:'',result:'Normal',resultNumber:0.5,action:'No further action',outcome:'',cancerDiagnosis:''},7 {hospitalNumber:'4160722512',age:55,ethnicity:'British',familyHistory:'Negative',selfReferral:'Yes',symptomatic:'Asymptomatic',DRE:'',adviceGiven:'',result:'Normal',resultNumber:1.1,action:'No further action',outcome:'',cancerDiagnosis:'QuesitionnIRE completed , advice given'},8 {hospitalNumber:'4287842421',age:55,ethnicity:'British',familyHistory:'Not discussed',selfReferral:'No',symptomatic:'Symptomatic LUTS ED',DRE:'',adviceGiven:'',result:'Normal',resultNumber:0.4,action:'No further action',outcome:'',cancerDiagnosis:''},9 {hospitalNumber:'4160718043',age:55,ethnicity:'British',familyHistory:'Negative',selfReferral:'Yes',symptomatic:'Asynptomatic',DRE:'',adviceGiven:'',result:'Normal',resultNumber:0.8,action:'No further action',outcome:'',cancerDiagnosis:''},10 {hospitalNumber:'4104742740',age:55,ethnicity:'British',familyHistory:'Negative',selfReferral:'Yes',symptomatic:'Asymptomatic',DRE:'',adviceGiven:'',result:'Normal',resultNumber:2.8,action:'No further action',outcome:'',cancerDiagnosis:''},11 {hospitalNumber:'4242917430',age:55,ethnicity:'British',familyHistory:'Not discussed',selfReferral:'No',symptomatic:'ED',DRE:'',adviceGiven:'',result:'Normal',resultNumber:1.6,action:'No further action',outcome:'',cancerDiagnosis:'Has been urgently referred in 2018'},12 {hospitalNumber:'4089143411',age:55,ethnicity:'British',familyHistory:'Not discussed',selfReferral:'No',symptomatic:'LTC',DRE:'',adviceGiven:'',result:'Normal',resultNumber:0.2,action:'No further action',outcome:'',cancerDiagnosis:''},13 {hospitalNumber:'4045004963',age:56,ethnicity:'British',familyHistory:'Not discussed',selfReferral:'No',symptomatic:'Annual Asymptomatic',DRE:'',adviceGiven:'',result:'Normal',resultNumber:1.9,action:'No further action',outcome:'',cancerDiagnosis:''},14 {hospitalNumber:'4160688632',age:56,ethnicity:'British',familyHistory:'Not discussed',selfReferral:'No',symptomatic:'Back pain',DRE:'',adviceGiven:'',result:'Normal',resultNumber:0.2,action:'No further action',outcome:'',cancerDiagnosis:''},15 // ... (all other patients from the new dataset)16 {hospitalNumber:'4842371951',age:64,ethnicity:'British',familyHistory:'Positive',selfReferral:'Yes',symptomatic:'Asymptomatic',DRE:'Not done',adviceGiven:'Given',result:'Normal',resultNumber:0.9,action:'No further action',outcome:'',cancerDiagnosis:''},17 {hospitalNumber:'6251172827',age:64,ethnicity:'Pakistani',familyHistory:'Not discussed',selfReferral:'No',symptomatic:'LUTS',DRE:'',adviceGiven:'',result:'Abnormal',resultNumber:4.3,action:'Urgent referral',outcome:'Reassured',cancerDiagnosis:''},18 {hospitalNumber:'6302185351',age:64,ethnicity:'British',familyHistory:'Not discussed',selfReferral:'',symptomatic:'LTC',DRE:'',adviceGiven:'',result:'Normal',resultNumber:0.9,action:'No further action',outcome:'',cancerDiagnosis:''},19 {hospitalNumber:'6286314261',age:65,ethnicity:'Pakistani',familyHistory:'Negative',selfReferral:'Yes',symptomatic:'IPSS 22',DRE:'Not done',adviceGiven:'',result:'Normal',resultNumber:1,action:'No further action',outcome:'',cancerDiagnosis:''},20 {hospitalNumber:'4849040268',age:65,ethnicity:'British',familyHistory:'Not discussed',selfReferral:'No',symptomatic:'LTC, Annual PSA',DRE:'Not done',adviceGiven:'Not given',result:'Abnormal',resultNumber:5.3,action:'No further action',outcome:'Annual Check , referral if > 11',cancerDiagnosis:''},21 {hospitalNumber:'4849093043',age:65,ethnicity:'British',familyHistory:'Not discussed',selfReferral:'No',symptomatic:'PSA monitoring',DRE:'Not done',adviceGiven:'Not given',result:'Normal',resultNumber:1.3,action:'No further action',outcome:'',cancerDiagnosis:''},22 {hospitalNumber:'4848958555',age:65,ethnicity:'British',familyHistory:'Negative',selfReferral:'Yes',symptomatic:'Asymptomatic - LTC',DRE:'Not done',adviceGiven:'Not given',result:'Normal',resultNumber:1.4,action:'No further action',outcome:'',cancerDiagnosis:''},23 {hospitalNumber:'4821267012',age:65,ethnicity:'British',familyHistory:'Not discussed',selfReferral:'No',symptomatic:'LTC',DRE:'Not done',adviceGiven:'Not given',result:'Normal',resultNumber:1.3,action:'No further action',outcome:'',cancerDiagnosis:''},24 {hospitalNumber:'4823025482',age:65,ethnicity:'British',familyHistory:'Not discussed',selfReferral:'No',symptomatic:'Feeling tired, hot',DRE:'Not done',adviceGiven:'Not given',result:'Normal',resultNumber:0.4,action:'No further action',outcome:'DE=RE done, enlarged prostate',cancerDiagnosis:''},25 {hospitalNumber:'4849091679',age:65,ethnicity:'British',familyHistory:'Negative',selfReferral:'Yes',symptomatic:'Asymptomatic',DRE:'Done',adviceGiven:'Given',result:'Abnormal',resultNumber:4.6,action:'Urgent referral',outcome:'Has annual review , advised to refer if > 10.8 , but they refer ?',cancerDiagnosis:''},26 {hospitalNumber:'4848761018',age:65,ethnicity:'British',familyHistory:'Not discussed',selfReferral:'No',symptomatic:'Annual PSA',DRE:'',adviceGiven:'',result:'Abnormal',resultNumber:4.9,action:'No further action',outcome:'To refer back if PSA > 9.7',cancerDiagnosis:''}27 ];28 29 // Calculate statistics from the data30 const totalPatients = tableData.length;31 const cancerCases = tableData.filter(p => p.cancerDiagnosis && p.cancerDiagnosis.toLowerCase().includes('cancer')).length;32 const asymptomatic = tableData.filter(p => p.symptomatic && p.symptomatic.toLowerCase().includes('asymptomatic')).length;33 const selfReferrals = tableData.filter(p => p.selfReferral === 'Yes').length;34 35 // Update the stats cards36 document.querySelectorAll('stats-card').forEach(card => {37 const title = card.getAttribute('title');38 if (title === 'Total Patients') card.setAttribute('value', totalPatients);39 if (title === 'Cancer Cases') card.setAttribute('value', cancerCases);40 if (title === 'Asymptomatic') card.setAttribute('value', asymptomatic);41 if (title === 'Self Referrals') card.setAttribute('value', selfReferrals);42 });43 44 // Initialize charts with new data45 initSymptomaticChart(tableData);46 initReferralChart(tableData);47 initAgeChart(tableData);48 49 // Render table data50 const table = document.querySelector('custom-data-table');51 if (table) {52 table.data = tableData;53 }54});55{56 hospitalNumber: '4162442959',57 age: 55,58 ethnicity: 'British',59 familyHistory: 'Not discussed',60 selfReferral: 'No',61 symptomatic: 'Symp Erectile dysf',62 result: 'Normal',63 resultNumber: 0.5,64 action: 'No further action',65 outcome: '',66 cancerDiagnosis: ''67 },68 // ... (continued with all the data rows from the spreadsheet)69 // Note: I'm showing the first 2 entries as example, but in the actual file70 // we would include all 150+ entries from the spreadsheet with all fields71 {72 hospitalNumber: '4702647660',73 age: 95,74 ethnicity: 'British white',75 familyHistory: 'Not discussed',76 selfReferral: 'No',77 symptomatic: 'Asymptomatic Long term C',78 result: 'Normal',79 resultNumber: 2.9,80 action: 'No further action',81 outcome: '',82 cancerDiagnosis: ''83 }84 ];85 86 // Calculate statistics from the data87 const totalPatients = tableData.length;88 const cancerCases = tableData.filter(p => p.cancerDiagnosis === 'Yes').length;89 const asymptomatic = tableData.filter(p => p.symptomatic.toLowerCase().includes('asymptomatic')).length;90 const selfReferrals = tableData.filter(p => p.selfReferral === 'Yes').length;91// Render table data92 const table = document.querySelector('custom-data-table');93 if (table) {94 table.data = tableData;95 }96});97function initSymptomaticChart(data) {98 const ctx = document.getElementById('symptomaticChart').getContext('2d');99 const asymptomaticCount = data.filter(p => p.symptomatic && p.symptomatic.toLowerCase().includes('asymptomatic')).length;100 const symptomaticCount = data.length - asymptomaticCount;101new Chart(ctx, {102 type: 'doughnut',103 data: {104 labels: ['Asymptomatic', 'Symptomatic'],105 datasets: [{106 data: [asymptomaticCount, symptomaticCount],107backgroundColor: [108 'rgba(124, 58, 237, 0.8)',109 'rgba(59, 130, 246, 0.8)'110 ],111 borderColor: [112 'rgba(124, 58, 237, 1)',113 'rgba(59, 130, 246, 1)'114 ],115 borderWidth: 1116 }]117 },118 options: {119 responsive: true,120 plugins: {121 legend: {122 position: 'bottom',123 },124 tooltip: {125 callbacks: {126 label: function(context) {127 return `${context.label}: ${context.raw} (${Math.round(context.raw/data.length*100)}%)`;128}129 }130 }131 }132 }133 });134}135function initReferralChart(data) {136 const ctx = document.getElementById('referralChart').getContext('2d');137 const selfReferralCount = data.filter(p => p.selfReferral === 'Yes').length;138 const nonSelfReferralCount = data.length - selfReferralCount;139new Chart(ctx, {140 type: 'bar',141 data: {142 labels: ['Self Referral', 'Non-Self Referral'],143 datasets: [{144 label: 'Count',145 data: [selfReferralCount, nonSelfReferralCount],146backgroundColor: [147 'rgba(16, 185, 129, 0.8)',148 'rgba(239, 68, 68, 0.8)'149 ],150 borderColor: [151 'rgba(16, 185, 129, 1)',152 'rgba(239, 68, 68, 1)'153 ],154 borderWidth: 1155 }]156 },157 options: {158 responsive: true,159 scales: {160 y: {161 beginAtZero: true162 }163 },164 plugins: {165 legend: {166 display: false167 }168 }169 }170 });171}172function initAgeChart(data) {173 const ctx = document.getElementById('ageChart').getContext('2d');174 175 // Calculate age group distribution176 const ageGroups = {177 '55-59': data.filter(p => p.age >= 55 && p.age <= 59).length,178 '60-64': data.filter(p => p.age >= 60 && p.age <= 64).length,179 '65-69': data.filter(p => p.age >= 65 && p.age <= 69).length180 };181new Chart(ctx, {182 type: 'line',183 data: {184 labels: Object.keys(ageGroups),185 datasets: [{186 label: 'Patients by Age Group',187 data: Object.values(ageGroups),188fill: false,189 backgroundColor: 'rgba(79, 70, 229, 0.8)',190 borderColor: 'rgba(79, 70, 229, 1)',191tension: 0.3192 }]193 },194 options: {195 responsive: true,196 plugins: {197 legend: {198 position: 'top',199 }200 },201 scales: {202 y: {203 beginAtZero: true204 }205 }206 }207 });208}