// Wait for component to be defined
customElements.whenDefined('sofia-sdk').then(() => {
const sofiaComponent = document.getElementById('sofia-component');
const toggleButton = document.getElementById('toggle-sofia');
// Configure callback to receive reports
sofiaComponent.handleReport = (report) => {
console.log('Clinical report received:', report);
// Process report according to your needs
displayReport(report);
sendToEHR(report);
};
// Configure callback for visibility changes
sofiaComponent.setIsOpen = (isOpen) => {
console.log('Component state:', isOpen ? 'Open' : 'Closed');
sofiaComponent.isopen = isOpen;
toggleButton.textContent = isOpen ? 'Close SofIA' : 'Open SofIA';
};
// Handle button click
toggleButton.addEventListener('click', () => {
const currentState = sofiaComponent.isopen === 'true';
sofiaComponent.isopen = !currentState;
});
});
// Function to display report in interface
function displayReport(report) {
const reportContainer = document.getElementById('report-display');
if (reportContainer) {
reportContainer.innerHTML = `
<h3>Clinical Report</h3>
<pre>${JSON.stringify(report, null, 2)}</pre>
`;
}
}
// Function to send to EHR/HIS system
function sendToEHR(report) {
// Implement integration with your system
fetch('/api/clinical-reports', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(report)
}).then(response => {
console.log('Report sent to EHR:', response.status);
}).catch(error => {
console.error('Error sending report:', error);
});
}