Skip to content

Commit

Permalink
Fix crash on invalid StudyDate
Browse files Browse the repository at this point in the history
  • Loading branch information
jennydaman committed Sep 26, 2024
1 parent 2df2851 commit e8ddeef
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/components/Pacs/components/StudyDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const StudyDetails: React.FC<{
<span>
Study "{study.StudyDescription}"{" "}
<span style={{ fontWeight: "initial" }}>
on {study.StudyDate ? format(study.StudyDate, dateFormat) : "unknown"}{" "}
on {formatDate(study.StudyDate, dateFormat)}{" "}
{study.AccessionNumber &&
!study.AccessionNumber.includes("no value provided") && (
<>(AccessionNumber: {study.AccessionNumber})</>
Expand Down Expand Up @@ -72,4 +72,16 @@ function formatPypxSex(dicomSex: string) {
}
}

function formatDate(date: Date | undefined | null, dateFormat: string) {
if (!date) {
return "unknown date";
}
try {
return format(date, dateFormat);
} catch (_e) {
// invalid date
return "unknown date";
}
}

export default StudyDetails;

0 comments on commit e8ddeef

Please sign in to comment.