-
Notifications
You must be signed in to change notification settings - Fork 451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug-Fix: Patient's Age parsing discrepancy during XLS export in Sample Management System #9247
base: develop
Are you sure you want to change the base?
Conversation
WalkthroughThe changes in this pull request focus on the Changes
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
✅ Deploy Preview for care-ohc ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (1)
src/components/Patient/SampleViewAdmin.tsx (1)
127-138
: Consider adding type safety for date fields.The date formatting could fail if the input is not a valid date string. Consider adding validation:
const columns = row.split(",").map((field, index) => { const header = headerColumns[index]?.trim(); if (header === "Patient Age") { return field.trim(); } if (header === "Date of Sample" || header === "Date of Result") { - return formatDateTime(field.trim()); + const trimmedField = field.trim(); + if (!trimmedField) { + return ""; + } + try { + return formatDateTime(trimmedField); + } catch (error) { + console.error(`Invalid date format for ${header}: ${trimmedField}`); + return trimmedField; + } } return field.includes(",") ? `"${field.trim()}"` : field.trim(); });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
src/components/Patient/SampleViewAdmin.tsx
(1 hunks)
🔇 Additional comments (2)
src/components/Patient/SampleViewAdmin.tsx (2)
120-143
: LGTM! The implementation fixes the age parsing issue.
The special handling for the "Patient Age" column correctly prevents age values from being misinterpreted as dates during export.
120-143
: Verify the fix across different age formats.
Let's verify that the age parsing works correctly for different age formats (e.g., "25", "25y", "2m", etc.) and edge cases.
✅ Verification successful
The age parsing implementation is safe and sufficient
The current implementation in parseExportData
simply trims the age field without any additional parsing or formatting, which is the correct approach because:
- The function only handles the CSV export formatting, where the age data is already validated and stored in the backend
- The implementation correctly preserves the original age value by only trimming whitespace
- No special age format parsing is needed during export since we want to maintain the original data format
The simple field.trim()
approach ensures that any age format (e.g., "25", "25y", "2m") will be preserved exactly as stored in the database, which is the desired behavior for data exports.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Search for age-related patterns in the codebase to understand supported formats
# Look for age-related patterns in test files
echo "Searching for age-related test cases..."
rg -l "Patient Age|patient_age" --type test
# Look for age validation or parsing logic
echo "Searching for age validation/parsing logic..."
rg "age|Age" --type typescript --type javascript
Length of output: 350
Script:
#!/bin/bash
# Search for age-related patterns in test files and source code
echo "Searching for age-related test cases and validation logic..."
rg -l "Patient Age|patient_age|parseAge"
# Look for specific age-related code with context
echo "Searching for age parsing/validation implementations..."
rg -A 5 "Patient Age|patient_age"
# Search for CSV export related tests
echo "Searching for CSV export tests..."
rg -A 10 "parseExportData|exportData.*csv"
Length of output: 2560
Script:
#!/bin/bash
# Search for test files related to SampleViewAdmin
echo "Searching for test files related to SampleViewAdmin..."
fd -e test.tsx -e test.ts -e spec.tsx -e spec.ts SampleViewAdmin
# Look for CSV-related test data or mock data
echo "Searching for CSV test data or mock data..."
rg -A 5 "csv|CSV" --type tsx --type ts
# Look for the actual component implementation to see how age is handled in the table
echo "Searching for table implementation with age column..."
rg -A 10 "columns.*Patient Age" --type tsx --type ts
Length of output: 551
Script:
#!/bin/bash
# Search for test files and CSV-related content without file type restrictions
echo "Searching for SampleViewAdmin tests..."
find . -type f -name "*SampleViewAdmin*test*" -o -name "*SampleViewAdmin*spec*"
echo "Searching for CSV and age-related patterns..."
rg -A 5 'csv|CSV|"Patient Age"'
# Look for any table or column definitions
echo "Searching for table column definitions..."
ast-grep --pattern 'const columns = [
$$$
{
$$$
title: "Patient Age",
$$$
},
$$$
]'
Length of output: 35874
const parseExportData = (data: string) => { | ||
const rows = data.trim().split("\n"); | ||
const headerColumns = rows[0].split(","); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add input validation and error handling.
The function should validate input and handle edge cases:
- Empty/malformed input
- Missing required headers
const parseExportData = (data: string) => {
+ if (!data?.trim()) {
+ throw new Error("Export data is empty or invalid");
+ }
+
const rows = data.trim().split("\n");
+ if (rows.length < 2) {
+ throw new Error("Export data must contain headers and at least one row");
+ }
+
const headerColumns = rows[0].split(",");
+ const requiredHeaders = ["Patient Age", "Date of Sample", "Date of Result"];
+ const missingHeaders = requiredHeaders.filter(
+ (header) => !headerColumns.some((h) => h.trim() === header)
+ );
+ if (missingHeaders.length > 0) {
+ throw new Error(`Missing required headers: ${missingHeaders.join(", ")}`);
+ }
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
const parseExportData = (data: string) => { | |
const rows = data.trim().split("\n"); | |
const headerColumns = rows[0].split(","); | |
const parseExportData = (data: string) => { | |
if (!data?.trim()) { | |
throw new Error("Export data is empty or invalid"); | |
} | |
const rows = data.trim().split("\n"); | |
if (rows.length < 2) { | |
throw new Error("Export data must contain headers and at least one row"); | |
} | |
const headerColumns = rows[0].split(","); | |
const requiredHeaders = ["Patient Age", "Date of Sample", "Date of Result"]; | |
const missingHeaders = requiredHeaders.filter( | |
(header) => !headerColumns.some((h) => h.trim() === header) | |
); | |
if (missingHeaders.length > 0) { | |
throw new Error(`Missing required headers: ${missingHeaders.join(", ")}`); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Hii @nihal467 please check if this is good to go. :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but I'd have recommended building a reusable utility function that could do something like shown, but this is also fine for now.
transformCSVData(
data,
{
dateFields: ['field1', 'field2'],
customTransforms: [
['field1']: (cell) => output
]
}
)
Proposed Changes
@ohcnetwork/care-fe-code-reviewers
Screenshots of the fix :
Merge Checklist
@Jacobjeevan Please have a look if this is good to go. Thank You :)
Summary by CodeRabbit
New Features
Bug Fixes