Skip to content

Commit

Permalink
MHV-60285 blue-button-txt-updates (#33443)
Browse files Browse the repository at this point in the history
  • Loading branch information
tynyttie authored Dec 11, 2024
1 parent 175b678 commit 7519e28
Show file tree
Hide file tree
Showing 7 changed files with 276 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ const DownloadRecordsPage = ({ runningUnitTest }) => {
allergies,
conditions,
vitals,
medications,
appointments,
demographics,
militaryService,
accountSummary,
])
) {
dispatch(getBlueButtonReportData());
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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')}
`;
};
Original file line number Diff line number Diff line change
@@ -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}
`;
};
15 changes: 15 additions & 0 deletions src/applications/mhv-medical-records/util/txtHelpers/blueButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
/**
Expand Down Expand Up @@ -42,12 +47,22 @@ ${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)}
${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)}
`;
};
Original file line number Diff line number Diff line change
@@ -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
`;
};
Original file line number Diff line number Diff line change
@@ -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')}
`;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const parseMilitaryService = records => {
const militaryServiceText = records;

return `
10) Military Service
Title: DOD Military Service Information
${militaryServiceText}
`;
};

0 comments on commit 7519e28

Please sign in to comment.