diff --git a/src/applications/mhv-medical-records/containers/DownloadRecordsPage.jsx b/src/applications/mhv-medical-records/containers/DownloadRecordsPage.jsx index a716f8b1cfdd..30c0aad469b2 100644 --- a/src/applications/mhv-medical-records/containers/DownloadRecordsPage.jsx +++ b/src/applications/mhv-medical-records/containers/DownloadRecordsPage.jsx @@ -153,6 +153,11 @@ const DownloadRecordsPage = ({ runningUnitTest }) => { allergies, conditions, vitals, + medications, + appointments, + demographics, + militaryService, + accountSummary, ]) ) { dispatch(getBlueButtonReportData()); @@ -165,18 +170,36 @@ const DownloadRecordsPage = ({ runningUnitTest }) => { allergies, conditions, vitals, + medications, + appointments, + demographics, + militaryService, + accountSummary, }; - const pdfName = `VA-Blue-Button-report-${getNameDateAndTime(user)}`; + const title = 'Blue Button report'; + const subject = 'VA Medical Record'; + const pdfName = `VA-Blue-Button-report-${getNameDateAndTime( + user, + title, + subject, + )}`; const content = getTxtContent(recordData, user); generateTextFile(content, pdfName, user); } }, [ + accountSummary, allergies, + appointments, conditions, + demographics, dispatch, + dob, labsAndTests, + medications, + militaryService, + name, notes, user, vaccines, diff --git a/src/applications/mhv-medical-records/util/txtHelpers/accountSummary.js b/src/applications/mhv-medical-records/util/txtHelpers/accountSummary.js new file mode 100644 index 000000000000..7c56f7c6e693 --- /dev/null +++ b/src/applications/mhv-medical-records/util/txtHelpers/accountSummary.js @@ -0,0 +1,50 @@ +import { generateAccountSummaryContent } from '../pdfHelpers/accountSummary'; + +// Function to parse account summaries +export const parseAccountSummary = records => { + // Generate the structured content + const accountSummaryContent = generateAccountSummaryContent(records || {}); + + // Initialize an array to hold the formatted text + const formattedText = []; + + // Process 'details' section if it exists + if ( + accountSummaryContent.details && + Array.isArray(accountSummaryContent.details.items) + ) { + accountSummaryContent.details.items.forEach(item => { + const title = item.title || 'Unknown'; + const value = item.value || 'No information provided'; + formattedText.push(`${title}: ${value}`); + }); + } + + // Process 'results' section if it exists + if ( + accountSummaryContent.results && + Array.isArray(accountSummaryContent.results.items) + ) { + formattedText.push('\nVA Treatment Facilities:'); + accountSummaryContent.results.items.forEach(facility => { + const header = facility.header || 'Unknown Facility'; + formattedText.push(`\n${header}:`); + if (Array.isArray(facility.items)) { + facility.items.forEach(item => { + const title = item.title || 'Unknown'; + const value = item.value || 'No information provided'; + formattedText.push(` ${title}: ${value}`); + }); + } + }); + } + + // Join the formatted text array into a single string + return ` +11) Account Summary + +My HealtheVet account summary + +${formattedText.join('\n')} +`; +}; diff --git a/src/applications/mhv-medical-records/util/txtHelpers/appointments.js b/src/applications/mhv-medical-records/util/txtHelpers/appointments.js new file mode 100644 index 000000000000..478b3bb29fe2 --- /dev/null +++ b/src/applications/mhv-medical-records/util/txtHelpers/appointments.js @@ -0,0 +1,75 @@ +import { generateAppointmentsContent } from '../pdfHelpers/appointments'; + +// Helper function to format appointment content into plain text +const formatAppointmentsContentToText = content => { + const sections = content.results.items; + + // Preface text + const { preface } = content.results; + + // Format each appointment section into plain text + const formattedSections = sections + .map(section => { + const header = `Date: ${section.header || 'Unknown Date'}`; + const itemsText = section.items + .map(item => { + // Check if item.value is an array of objects + if ( + Array.isArray(item.value) && + item.value.every(val => typeof val === 'object') + ) { + // Format each object in the array + const formattedValues = item.value + .map(val => { + return Object.entries(val) + .map(([key, value]) => `${key}: ${value}`) + .join(', '); + }) + .join('\n'); + return `${item.title}:\n${formattedValues}`; + } + // For other types, display as usual + return `${item.title}: ${item.value || 'No information provided'}`; + }) + .join('\n'); // Join each item with a newline + + return `${header}\n${itemsText}`; + }) + .join('\n\n'); // Separate sections with double newlines + + return `${preface}\n\n${formattedSections}`; +}; + +// Main function +export const parseAppointments = appointments => { + // Filter appointments into upcoming and past + const upcomingAppointments = appointments.filter( + appointment => appointment.isUpcoming, + ); + const pastAppointments = appointments.filter( + appointment => !appointment.isUpcoming, + ); + + // Generate content for upcoming and past appointments + const upcomingContent = generateAppointmentsContent(upcomingAppointments); + const pastContent = generateAppointmentsContent(pastAppointments); + + // Format content into plain text + const formattedUpcomingContent = formatAppointmentsContentToText( + upcomingContent, + ); + const formattedPastContent = formatAppointmentsContentToText(pastContent); + + return ` +8) Appointments + +'Your VA appointments may be by telephone, video, or in person. Always bring your insurance information with you to your appointment.', + +Records: +- Upcoming Appointments: +${formattedUpcomingContent} + +- Past Appointments: +${formattedPastContent} +`; +}; diff --git a/src/applications/mhv-medical-records/util/txtHelpers/blueButton.js b/src/applications/mhv-medical-records/util/txtHelpers/blueButton.js index 79e77436df85..109d446a3054 100644 --- a/src/applications/mhv-medical-records/util/txtHelpers/blueButton.js +++ b/src/applications/mhv-medical-records/util/txtHelpers/blueButton.js @@ -8,6 +8,11 @@ import { parseVaccines } from './vaccines'; import { parseAllergies } from './allergies'; import { parseHealthConditions } from './conditions'; import { parseVitals } from './vitals'; +import { parseMedications } from './medications'; +import { parseAppointments } from './appointments'; +import { parseDemographics } from './demographics'; +import { parseMilitaryService } from './militaryService'; +import { parseAccountSummary } from './accountSummary'; // TODO: figure out a way to reduce complexity of the functions in this file /** @@ -42,6 +47,11 @@ ${txtLineDotted} 4. Allergies 5. Health Conditions 6. Vitals + 7. Medications, + 8. Appointments, + 9. Demographics, + 10. Military Service, + 11. Account Summary, ${parseLabsAndTests(data.labsAndTests)} ${parseCareSummariesAndNotes(data.notes)} @@ -49,5 +59,10 @@ ${parseVaccines(data.vaccines)} ${parseAllergies(data.allergies)} ${parseHealthConditions(data.conditions)} ${parseVitals(data.vitals)} +${parseMedications(data.medications)} +${parseAppointments(data.appointments)} +${parseDemographics(data.demographics)} +${parseMilitaryService(data.militaryService)} +${parseAccountSummary(data.accountSummary)} `; }; diff --git a/src/applications/mhv-medical-records/util/txtHelpers/demographics.js b/src/applications/mhv-medical-records/util/txtHelpers/demographics.js new file mode 100644 index 000000000000..4f137e7d51e9 --- /dev/null +++ b/src/applications/mhv-medical-records/util/txtHelpers/demographics.js @@ -0,0 +1,57 @@ +import { generateDemographicsContent } from '../pdfHelpers/demographics'; + +// Helper function to format the demographics content into plain text +const formatDemographicsContentToText = content => { + // Extract the `items` array from the nested structure + const sections = content.results.items; + + // Format each section into plain text + return sections + .map(section => { + // Extract the header (if any) and items in the section + const header = section.header ? `${section.header}:\n` : ''; + const itemsText = section.items + .map( + item => + `${item.title || 'Unknown'}: ${item.value || + 'No information provided'}`, + ) + .join('\n'); // Join item strings with newlines + + return `${header}${itemsText}`; + }) + .join('\n\n'); // Separate sections with double newlines +}; + +// Function to parse demographics +export const parseDemographics = records => { + return ` +9) Demographics + +Each of your VA facilities may have different demographic information for you. +If you need to update your information, contact your facility. + +${records + .map(record => { + // Generate content and format it as text + let demographicsContent; + try { + demographicsContent = generateDemographicsContent(record); + + // Format content into plain text + demographicsContent = formatDemographicsContentToText( + demographicsContent, + ); + } catch (error) { + demographicsContent = 'Error formatting demographics content'; + } + + return ` +VA Facility: ${record.facility || 'Unknown Facility'} +titleMoveDownAmount: 0.5, +${demographicsContent} + `; + }) + .join('\n\n')} // Add line breaks between records +`; +}; diff --git a/src/applications/mhv-medical-records/util/txtHelpers/medications.js b/src/applications/mhv-medical-records/util/txtHelpers/medications.js new file mode 100644 index 000000000000..92c238af3c72 --- /dev/null +++ b/src/applications/mhv-medical-records/util/txtHelpers/medications.js @@ -0,0 +1,44 @@ +import { generateMedicationsContent } from '../pdfHelpers/medications'; + +export const parseMedications = records => { + return ` +7) Medications + +This is a list of prescriptions and other medications in your VA medical records. +When you share your medications list with providers, make sure you also tell them +about your allergies and reactions to medications. When you download medications records, +we also include a list of allergies and reactions in your VA medical records. +Showing ${records.length} medications, alphabetically by name: + +${records + .map(record => { + const title = record.prescriptionName; + const content = generateMedicationsContent(record); + + // Check if content.details exists and is an array + const formattedDetails = content.details?.length + ? content.details + .map(detail => { + const header = `\n${detail.header}:\n`; + const items = detail.items + .map(item => { + if (item.title && item.value) { + return `- ${item.title}: ${item.value}`; + } + if (item.value) { + return `- ${item.value}`; + } + return ''; + }) + .join('\n'); + return `${header}${items}`; + }) + .join('\n\n') + : 'No details available for this record.'; + + // Combine title and formatted details + return `Title: ${title}\n${formattedDetails}`; + }) + .join('\n\n')} +`; +}; diff --git a/src/applications/mhv-medical-records/util/txtHelpers/militaryService.js b/src/applications/mhv-medical-records/util/txtHelpers/militaryService.js new file mode 100644 index 000000000000..fdfe079b9efd --- /dev/null +++ b/src/applications/mhv-medical-records/util/txtHelpers/militaryService.js @@ -0,0 +1,11 @@ +export const parseMilitaryService = records => { + const militaryServiceText = records; + + return ` +10) Military Service + +Title: DOD Military Service Information + +${militaryServiceText} +`; +};