Skip to content
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

Merged
merged 11 commits into from
Dec 11, 2024
40 changes: 24 additions & 16 deletions src/components/Patient/SampleViewAdmin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,30 @@ export default function SampleViewAdmin() {
});
};

const parseExportData = (data: string) =>
data
.trim()
.split("\n")
.map((row: string) =>
row
.trim()
.split(",")
.map((field: string) =>
new Date(field).toString() === "Invalid Date"
? field
: formatDateTime(field),
)
.join(","),
)
.join("\n");
const parseExportData = (data: string) => {
const rows = data.trim().split("\n");
pooranjoyb marked this conversation as resolved.
Show resolved Hide resolved
const headerColumns = rows[0].split(",");

pooranjoyb marked this conversation as resolved.
Show resolved Hide resolved
return [
rows[0],
...rows.slice(1).map((row) => {
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());
}
return field.includes(",") ? `"${field.trim()}"` : field.trim();
});

return columns.join(",");
}),
].join("\n");
};

let sampleList: any[] = [];
if (sampeleData?.count) {
Expand Down