From 8a67ea50e5bc0371c3aff67643958e8b385732c9 Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Thu, 12 Oct 2023 18:19:47 +0530 Subject: [PATCH 1/3] `formatDateTime`: hide time if 12AM --- src/Components/Facility/TreatmentSummary.tsx | 2 +- src/Components/Patient/PatientInfoCard.tsx | 2 +- src/Utils/utils.ts | 16 ++++++++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Components/Facility/TreatmentSummary.tsx b/src/Components/Facility/TreatmentSummary.tsx index 3fbd80ac8b2..34120fea861 100644 --- a/src/Components/Facility/TreatmentSummary.tsx +++ b/src/Components/Facility/TreatmentSummary.tsx @@ -139,7 +139,7 @@ const TreatmentSummary = (props: any) => { Date of admission : {consultationData.admitted - ? formatDate(consultationData.admission_date) + ? formatDateTime(consultationData.admission_date) : " --/--/----"} diff --git a/src/Components/Patient/PatientInfoCard.tsx b/src/Components/Patient/PatientInfoCard.tsx index 701b76b5e3a..be345c38f6b 100644 --- a/src/Components/Patient/PatientInfoCard.tsx +++ b/src/Components/Patient/PatientInfoCard.tsx @@ -239,7 +239,7 @@ export default function PatientInfoCard(props: { )?.text }{" "} on{" "} - {formatDate( + {formatDateTime( ["A", "DC"].includes(consultation?.suggestion ?? "") ? consultation?.admission_date : consultation?.created_date diff --git a/src/Utils/utils.ts b/src/Utils/utils.ts index 3aef5b03d67..b021aaa1b00 100644 --- a/src/Utils/utils.ts +++ b/src/Utils/utils.ts @@ -78,8 +78,20 @@ const DATE_TIME_FORMAT = `${TIME_FORMAT}; ${DATE_FORMAT}`; type DateLike = Parameters[0]; -export const formatDateTime = (date: DateLike, format = DATE_TIME_FORMAT) => - dayjs(date).format(format); +export const formatDateTime = (date: DateLike, format?: string) => { + const obj = dayjs(date); + + if (format) { + return obj.format(format); + } + + // formatDate if hours, minutes and seconds are 0 + if (obj.hour() === 0 && obj.minute() === 0 && obj.second() === 0) { + return obj.format(DATE_FORMAT); + } + + return obj.format(DATE_TIME_FORMAT); +}; export const formatDate = (date: DateLike, format = DATE_FORMAT) => formatDateTime(date, format); From e38206a59d4b354c864d27f194b0067c558afdea Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Thu, 12 Oct 2023 18:50:00 +0530 Subject: [PATCH 2/3] correct for timezone --- src/Utils/utils.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Utils/utils.ts b/src/Utils/utils.ts index b021aaa1b00..e9d8cbbc00c 100644 --- a/src/Utils/utils.ts +++ b/src/Utils/utils.ts @@ -85,8 +85,9 @@ export const formatDateTime = (date: DateLike, format?: string) => { return obj.format(format); } - // formatDate if hours, minutes and seconds are 0 - if (obj.hour() === 0 && obj.minute() === 0 && obj.second() === 0) { + // formatDate if hours, minutes and seconds are 0 (after timezone correction) + const utc = obj.subtract(obj.utcOffset(), "minute"); + if (utc.hour() === 0 && utc.minute() === 0 && utc.second() === 0) { return obj.format(DATE_FORMAT); } From 9c361bd9af1d3464004e73ab6abaa8e526d76cb4 Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Thu, 12 Oct 2023 18:58:13 +0530 Subject: [PATCH 3/3] Consultation Form: admission date as date time field --- src/Components/Facility/ConsultationForm.tsx | 29 ++++++++++++-------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/Components/Facility/ConsultationForm.tsx b/src/Components/Facility/ConsultationForm.tsx index 01a5f02b7b1..44637a68fbf 100644 --- a/src/Components/Facility/ConsultationForm.tsx +++ b/src/Components/Facility/ConsultationForm.tsx @@ -1145,17 +1145,24 @@ export const ConsultationForm = (props: any) => { className="col-span-6" ref={fieldRef["admission_date"]} > - + {state.form.suggestion === "DC" && ( + + )} + {state.form.suggestion === "A" && ( + + )} {!isUpdate && (