Skip to content

Commit

Permalink
Shows encounter duration in discharge confirmation dialog (#8124)
Browse files Browse the repository at this point in the history
* Shows encounter duration in discharge confirmation dialog

* correction for IP days

* update text of "IP Days" to "IP Day No"
  • Loading branch information
rithviknishad authored Jul 11, 2024
1 parent 0f5b54c commit ff70e5f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 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
2 changes: 1 addition & 1 deletion src/Components/Patient/ManagePatients.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ export const PatientManager = () => {
size="small"
variant="primary"
startIcon="l-clock-three"
text={`IP Days: ${dayjs().diff(patient.last_consultation.encounter_date, "day")}`}
text={`IP Day No: ${dayjs().diff(patient.last_consultation.encounter_date, "day") + 1}`}
/>
)}
{patient.gender === 2 &&
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Patient/PatientInfoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -559,12 +559,12 @@ export default function PatientInfoCard(props: {
{dayjs(consultation.discharge_date || undefined).diff(
consultation.encounter_date,
"day",
)}
) + 1}
</span>
</div>
</div>
<span className="mt-1 text-xs font-medium text-gray-700">
IP Days
IP Day No
</span>
</div>
)}
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 ff70e5f

Please sign in to comment.