Introduction
Epic MyChart is a patient portal that provides secure online access to medical records, test results, appointments, and health information. While Epic offers some API access through FHIR standards, browser automation provides a powerful alternative for exporting comprehensive patient data, accessing medical records, scheduling appointments, and automating healthcare workflows when API access is limited or unavailable.
Why Use Browser Automation for Epic MyChart Data Export?
- Limited API Access: Epic MyChart has restricted API access for individual patients and certain features
- Dashboard-Only Features: Some medical records, test results, and appointment scheduling are only available through the web portal
- Historical Data: Easier access to older medical records and test results beyond API limits
- Custom Reports: Generate reports with specific date ranges, record types, and filters
- Medical Records: Export complete medical history for personal records or second opinions
- Appointment Management: Automate appointment scheduling and reminders
- Test Results: Collect and organize lab results and diagnostic reports
Setting Up Epic MyChart Data Export Automation
Here's how to automate data collection from Epic MyChart using browser automation:
import { chromium } from 'playwright';
const response = await fetch("https://api.anchorbrowser.io/api/sessions", {
method: "POST",
headers: {
"anchor-api-key": "YOUR_API_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
'headless': false,
'proxy': {
'type': 'residential',
'country': 'US'
}
}),
});
const { id } = await response.json();
const connectionString = `wss://connect.anchorbrowser.io?apiKey=YOUR_API_KEY&sessionId=${id}`;
const browser = await chromium.connectOverCDP(connectionString);
const context = browser.contexts()[0];
const ai = context.serviceWorkers()[0];
const page = context.pages()[0];
// Navigate to Epic MyChart (URL varies by healthcare provider)
await page.goto("https://mychart.example.com");
// Login with AI agent
await ai.evaluate(JSON.stringify({
prompt: 'Log in to MyChart using the provided credentials. Wait for the dashboard to fully load.'
}));
Exporting Medical Records
Automate the export of medical records from Epic MyChart:
const exportMyChartRecords = async (page, ai, dateRange) => {
// Navigate to medical records section
await ai.evaluate(JSON.stringify({
prompt: 'Navigate to the Medical Records or Health Records section in MyChart'
}));
// Set date filter
await ai.evaluate(JSON.stringify({
prompt: `Set the date filter to ${dateRange.start} to ${dateRange.end}`
}));
// Export records
await ai.evaluate(JSON.stringify({
prompt: 'Click Download or Export, select the desired format (PDF, CSV, or JSON), and wait for the download to complete.'
}));
// Wait for download
const download = await page.waitForEvent('download');
const path = await download.path();
return path;
};
Collecting Test Results
Extract lab results and diagnostic reports:
const collectMyChartTestResults = async (page, ai) => {
await ai.evaluate(JSON.stringify({
prompt: 'Navigate to the Test Results or Lab Results section'
}));
// Extract test results
const testResults = await ai.evaluate(JSON.stringify({
prompt: 'Extract all test results including: test names, dates, values, reference ranges, and provider notes. Return as structured JSON data.'
}));
return testResults;
};
Exporting Appointment History
Download appointment history and upcoming appointments:
const exportMyChartAppointments = async (page, ai, dateRange) => {
await ai.evaluate(JSON.stringify({
prompt: 'Navigate to the Appointments or Visits section'
}));
// Set date filter
await ai.evaluate(JSON.stringify({
prompt: `Filter appointments by date range ${dateRange.start} to ${dateRange.end}`
}));
// Export appointment data
await ai.evaluate(JSON.stringify({
prompt: 'Export appointment history including: dates, times, providers, visit types, and notes'
}));
const download = await page.waitForEvent('download');
return await download.path();
};
Collecting Medication Lists
Extract current medications and prescription history:
const exportMyChartMedications = async (page, ai) => {
await ai.evaluate(JSON.stringify({
prompt: 'Navigate to the Medications or Current Medications section'
}));
await ai.evaluate(JSON.stringify({
prompt: 'Export medication list including: medication names, dosages, frequencies, prescribers, start dates, and instructions'
}));
const download = await page.waitForEvent('download');
return await download.path();
};
Exporting Immunization Records
Download vaccination and immunization history:
const exportMyChartImmunizations = async (page, ai) => {
await ai.evaluate(JSON.stringify({
prompt: 'Navigate to the Immunizations or Vaccines section'
}));
await ai.evaluate(JSON.stringify({
prompt: 'Export immunization records including: vaccine names, dates, lot numbers, and administration sites'
}));
const download = await page.waitForEvent('download');
return await download.path();
};
Automating Appointment Scheduling
Schedule appointments automatically:
const scheduleMyChartAppointment = async (page, ai, appointmentDetails) => {
await ai.evaluate(JSON.stringify({
prompt: 'Navigate to the Schedule Appointment or Request Appointment section'
}));
// Fill appointment details
await ai.evaluate(JSON.stringify({
prompt: `Schedule an appointment with: provider ${appointmentDetails.provider}, date ${appointmentDetails.date}, time ${appointmentDetails.time}, reason ${appointmentDetails.reason}`
}));
// Confirm appointment
await ai.evaluate(JSON.stringify({
prompt: 'Review the appointment details and confirm the booking'
}));
// Get confirmation
const confirmation = await ai.evaluate(JSON.stringify({
prompt: 'Extract the appointment confirmation number and details'
}));
return confirmation;
};
Best Practices for Epic MyChart Automation
- Security: Use secure credential storage and enable 2FA handling
- HIPAA Compliance: Ensure all data handling meets HIPAA privacy and security requirements
- Rate Limiting: Add delays between requests to avoid account restrictions
- Data Validation: Verify exported data completeness before processing
- Error Handling: Implement retry logic for transient failures
- Provider-Specific URLs: MyChart URLs vary by healthcare provider - ensure you're using the correct portal
- Regular Updates: Monitor for changes in MyChart's interface and update scripts accordingly
Handling Authentication
Epic MyChart may require multi-factor authentication. Here's how to handle it:
const handleMyChartAuth = async (page, ai, credentials) => {
// Navigate to login (URL varies by provider)
await page.goto("https://mychart.example.com");
// Enter credentials
await ai.evaluate(JSON.stringify({
prompt: `Enter username: ${credentials.username} and password: ${credentials.password}, then click Login`
}));
// Handle 2FA if required
await ai.evaluate(JSON.stringify({
prompt: 'If a 2FA prompt appears, wait for the code to be provided and enter it, or click "Remember this device" if available'
}));
// Wait for dashboard
await page.waitForLoadState('networkidle');
};
Resources
- Anchor Browser Documentation - Complete API reference and guides
- Anchor Browser Playground - Try browser automation in your browser
Conclusion
Browser automation provides a flexible alternative to API access for Epic MyChart data export. By leveraging intelligent browser agents, you can automate comprehensive healthcare data collection workflows that aren't easily achievable through API calls alone. Whether you need medical records, test results, appointment history, medications, or immunization records, browser automation enables efficient data export from Epic MyChart while maintaining HIPAA compliance.
Start automating your Epic MyChart data collection today and streamline your healthcare data management workflows!