Skip to content

Commit

Permalink
Shows encounter duration in discharge confirmation dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
rithviknishad committed Jul 8, 2024
1 parent 2b9cb55 commit db2a95b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
24 changes: 22 additions & 2 deletions src/Components/Facility/DischargeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { FacilitySelect } from "../Common/FacilitySelect";
import { FacilityModel } from "./models";
import dayjs from "../../Utils/dayjs";
import { FieldError } from "../Form/FieldValidators";
import { useTranslation } from "react-i18next";

interface PreDischargeFormInterface {
new_discharge_reason: number | null;
Expand Down Expand Up @@ -57,6 +58,7 @@ const DischargeModal = ({
discharge_date = dayjs().format("YYYY-MM-DDTHH:mm"),
death_datetime = dayjs().format("YYYY-MM-DDTHH:mm"),
}: IProps) => {
const { t } = useTranslation();
const { enable_hcx } = useConfig();
const dispatch: any = useDispatch();
const [preDischargeForm, setPreDischargeForm] =
Expand Down Expand Up @@ -205,6 +207,19 @@ const DischargeModal = ({
}));
};

const encounterDuration = dayjs
.duration(
dayjs(
preDischargeForm[
discharge_reason ===
DISCHARGE_REASONS.find((i) => i.text == "Expired")?.id
? "death_datetime"
: "discharge_date"
],
).diff(consultationData.encounter_date),
)
.humanize();

return (
<DialogModal
title={
Expand Down Expand Up @@ -321,7 +336,6 @@ const DischargeModal = ({
: errors?.discharge_date
}
/>

{discharge_reason ===
DISCHARGE_REASONS.find((i) => i.text == "Recovered")?.id && (
<>
Expand Down Expand Up @@ -374,7 +388,13 @@ const DischargeModal = ({
</div>
)}

<div className="flex flex-col gap-2 pt-4 md:flex-row md:justify-end">
<div className="py-4">
<span className="text-gray-700">
{t("encounter_duration_confirmation")}{" "}
<strong>{encounterDuration}</strong>.
</span>
</div>
<div className="cui-form-button-group">
<Cancel onClick={onClose} />
{isSendingDischargeApi ? (
<CircularProgress />
Expand Down
3 changes: 2 additions & 1 deletion src/Locale/en/Consultation.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@
"prev_sessions": "Prev Sessions",
"next_sessions": "Next Sessions",
"no_changes": "No changes",
"encounter_suggestion_edit_disallowed": "Not allowed to switch to this option in edit consultation"
"encounter_suggestion_edit_disallowed": "Not allowed to switch to this option in edit consultation",
"encounter_duration_confirmation": "The duration of this encounter would be"
}

0 comments on commit db2a95b

Please sign in to comment.