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 && ( 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..e9d8cbbc00c 100644 --- a/src/Utils/utils.ts +++ b/src/Utils/utils.ts @@ -78,8 +78,21 @@ 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 (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); + } + + return obj.format(DATE_TIME_FORMAT); +}; export const formatDate = (date: DateLike, format = DATE_FORMAT) => formatDateTime(date, format);