From ff70e5f9e4d605410fd9676c2c80c74a1f77a2e5 Mon Sep 17 00:00:00 2001 From: Rithvik Nishad Date: Thu, 11 Jul 2024 12:20:38 +0530 Subject: [PATCH 1/3] Shows encounter duration in discharge confirmation dialog (#8124) * Shows encounter duration in discharge confirmation dialog * correction for IP days * update text of "IP Days" to "IP Day No" --- src/Components/Facility/DischargeModal.tsx | 24 ++++++++++++++++++++-- src/Components/Patient/ManagePatients.tsx | 2 +- src/Components/Patient/PatientInfoCard.tsx | 4 ++-- src/Locale/en/Consultation.json | 3 ++- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/Components/Facility/DischargeModal.tsx b/src/Components/Facility/DischargeModal.tsx index 0be7b4eabd8..1476e38ed03 100644 --- a/src/Components/Facility/DischargeModal.tsx +++ b/src/Components/Facility/DischargeModal.tsx @@ -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; @@ -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] = @@ -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 ( - {discharge_reason === DISCHARGE_REASONS.find((i) => i.text == "Recovered")?.id && ( <> @@ -374,7 +388,13 @@ const DischargeModal = ({ )} -
+
+ + {t("encounter_duration_confirmation")}{" "} + {encounterDuration}. + +
+
{isSendingDischargeApi ? ( diff --git a/src/Components/Patient/ManagePatients.tsx b/src/Components/Patient/ManagePatients.tsx index c02efc5c737..9ddcb4b379c 100644 --- a/src/Components/Patient/ManagePatients.tsx +++ b/src/Components/Patient/ManagePatients.tsx @@ -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 && diff --git a/src/Components/Patient/PatientInfoCard.tsx b/src/Components/Patient/PatientInfoCard.tsx index a43d49a26ac..d3ad76bf661 100644 --- a/src/Components/Patient/PatientInfoCard.tsx +++ b/src/Components/Patient/PatientInfoCard.tsx @@ -559,12 +559,12 @@ export default function PatientInfoCard(props: { {dayjs(consultation.discharge_date || undefined).diff( consultation.encounter_date, "day", - )} + ) + 1}
- IP Days + IP Day No )} diff --git a/src/Locale/en/Consultation.json b/src/Locale/en/Consultation.json index 4df1a4de9a3..fa0a54290b0 100644 --- a/src/Locale/en/Consultation.json +++ b/src/Locale/en/Consultation.json @@ -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" } \ No newline at end of file From 9ad27807f5c948938c781a6548b9d902898f4824 Mon Sep 17 00:00:00 2001 From: Rithvik Nishad Date: Thu, 11 Jul 2024 12:41:58 +0530 Subject: [PATCH 2/3] Phone number field: Adds helper icon to improve how supported phone number types are shown (#8126) * Adds utility fn. to humanize strings * Adds helper to clarify supported phone number types in phone number field * update `humanizeStrings` implementation * correct icon for user register page * fix responsiveness * handle empty array gracefully --- .../Form/FormFields/PhoneNumberFormField.tsx | 41 ++++++++----------- src/Components/Users/UserAdd.tsx | 3 +- src/Locale/en/Common.json | 5 +++ src/Utils/utils.ts | 19 +++++++++ 4 files changed, 44 insertions(+), 24 deletions(-) diff --git a/src/Components/Form/FormFields/PhoneNumberFormField.tsx b/src/Components/Form/FormFields/PhoneNumberFormField.tsx index b2034507475..c580a15e409 100644 --- a/src/Components/Form/FormFields/PhoneNumberFormField.tsx +++ b/src/Components/Form/FormFields/PhoneNumberFormField.tsx @@ -7,6 +7,7 @@ import { formatPhoneNumber as formatPhoneNumberUtil, getCountryCode, CountryData, + humanizeStrings, } from "../../../Utils/utils"; import phoneCodesJson from "../../../Common/static/countryPhoneAndFlags.json"; import { @@ -14,8 +15,9 @@ import { PhoneNumberValidator, PhoneNumberType, } from "../FieldValidators"; -import CareIcon, { IconName } from "../../../CAREUI/icons/CareIcon"; +import CareIcon from "../../../CAREUI/icons/CareIcon"; import { Popover } from "@headlessui/react"; +import { useTranslation } from "react-i18next"; const phoneCodes: Record = phoneCodesJson; @@ -154,29 +156,22 @@ export default function PhoneNumberFormField(props: Props) { ); } -const phoneNumberTypeIcons: Record = { - international_mobile: "l-globe", - indian_mobile: "l-mobile-android", - mobile: "l-mobile-android", - landline: "l-phone", - support: "l-headset", -}; +const PhoneNumberTypesHelp = (props: { types: PhoneNumberType[] }) => { + const { t } = useTranslation(); -const PhoneNumberTypesHelp = ({ types }: { types: PhoneNumberType[] }) => ( -
- {types.map((type) => ( - - - - {type.replace("_", " ")} - - - ))} -
-); + return ( +
+ +
+ Supports only{" "} + + {humanizeStrings(props.types.map((item) => t(item)))} + {" "} + numbers. +
+
+ ); +}; const conditionPhoneCode = (code: string) => { code = code.split(" ")[0]; diff --git a/src/Components/Users/UserAdd.tsx b/src/Components/Users/UserAdd.tsx index f7e6b978fb9..bb8b1ea158d 100644 --- a/src/Components/Users/UserAdd.tsx +++ b/src/Components/Users/UserAdd.tsx @@ -608,7 +608,8 @@ export const UserAdd = (props: UserProps) => { className="inline-block rounded border border-gray-600 bg-gray-50 px-4 py-2 text-gray-600 transition hover:bg-gray-100" target="_blank" > -  Need Help? +  Need + Help? } backUrl="/users" diff --git a/src/Locale/en/Common.json b/src/Locale/en/Common.json index 019a51232ba..f6ee4f1032d 100644 --- a/src/Locale/en/Common.json +++ b/src/Locale/en/Common.json @@ -48,6 +48,11 @@ "filter": "Filter", "ordering": "Ordering", "phone_number": "Phone Number", + "international_mobile": "International Mobile", + "indian_mobile": "Indian Mobile", + "mobile": "Mobile", + "landline": "Indian landline", + "support": "Support", "emergency_contact_number": "Emergency Contact Number", "last_modified": "Last Modified", "patient_address": "Patient Address", diff --git a/src/Utils/utils.ts b/src/Utils/utils.ts index d599a494b1c..60c49da0dc9 100644 --- a/src/Utils/utils.ts +++ b/src/Utils/utils.ts @@ -454,3 +454,22 @@ export const isPostPartum = (data_of_delivery?: string) => { export const isAntenatal = (menstruation_start_date?: string) => { return dayjs().diff(menstruation_start_date, "month") <= 9; }; + +/** + * A utility method to format an array of string to human readable format. + * + * @param values Array of strings to be made human readable. + * @returns Human readable version of the list of strings + */ +export const humanizeStrings = (strings: readonly string[], empty = "") => { + if (strings.length === 0) { + return empty; + } + + if (strings.length === 1) { + return strings[0]; + } + + const [last, ...items] = [...strings].reverse(); + return `${items.reverse().join(", ")} and ${last}`; +}; From 6739c26240e8955effbbacd793aed290ba0baebb Mon Sep 17 00:00:00 2001 From: Rithvik Nishad Date: Thu, 11 Jul 2024 12:42:26 +0530 Subject: [PATCH 3/3] Add caution for encounter date field if date is beyond 30 days. (#8125) * Add caution for encounter date field if beyond 30 days. * add translations --- src/Components/Facility/ConsultationForm.tsx | 28 +++++++++++++------- src/Locale/en/Common.json | 3 ++- src/Locale/en/Consultation.json | 7 +++++ 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/Components/Facility/ConsultationForm.tsx b/src/Components/Facility/ConsultationForm.tsx index a728ffc805a..436f8f19e04 100644 --- a/src/Components/Facility/ConsultationForm.tsx +++ b/src/Components/Facility/ConsultationForm.tsx @@ -1230,16 +1230,9 @@ export const ConsultationForm = ({ facilityId, patientId, id }: Props) => { required={["A", "DC", "OP"].includes( state.form.suggestion, )} - label={ - { - A: "Date & Time of Admission to the Facility", - DC: "Date & Time of Domiciliary Care commencement", - OP: "Date & Time of Out-patient visit", - DD: "Date & Time of Consultation", - HI: "Date & Time of Consultation", - R: "Date & Time of Consultation", - }[state.form.suggestion] - } + label={t( + `encounter_date_field_label__${state.form.suggestion}`, + )} type="datetime-local" value={dayjs(state.form.encounter_date).format( "YYYY-MM-DDTHH:mm", @@ -1251,6 +1244,21 @@ export const ConsultationForm = ({ facilityId, patientId, id }: Props) => { : undefined } /> + {dayjs().diff(state.form.encounter_date, "day") > 30 && ( +
+ + + {t("caution")}:{" "} + {t("back_dated_encounter_date_caution")}{" "} + + {dayjs(state.form.encounter_date).fromNow()}. + + +
+ )} {state.form.route_to_facility === 30 && ( diff --git a/src/Locale/en/Common.json b/src/Locale/en/Common.json index f6ee4f1032d..a85572b8d04 100644 --- a/src/Locale/en/Common.json +++ b/src/Locale/en/Common.json @@ -171,5 +171,6 @@ "treating_doctor": "Treating Doctor", "ration_card__NO_CARD": "Non-card holder", "ration_card__BPL": "BPL", - "ration_card__APL": "APL" + "ration_card__APL": "APL", + "caution": "Caution" } \ No newline at end of file diff --git a/src/Locale/en/Consultation.json b/src/Locale/en/Consultation.json index fa0a54290b0..d811680d0fd 100644 --- a/src/Locale/en/Consultation.json +++ b/src/Locale/en/Consultation.json @@ -37,5 +37,12 @@ "next_sessions": "Next Sessions", "no_changes": "No changes", "encounter_suggestion_edit_disallowed": "Not allowed to switch to this option in edit consultation", + "encounter_date_field_label__A": "Date & Time of Admission to the Facility", + "encounter_date_field_label__DC": "Date & Time of Domiciliary Care commencement", + "encounter_date_field_label__OP": "Date & Time of Out-patient visit", + "encounter_date_field_label__DD": "Date & Time of Consultation", + "encounter_date_field_label__HI": "Date & Time of Consultation", + "encounter_date_field_label__R": "Date & Time of Consultation", + "back_dated_encounter_date_caution": "You are creating an encounter for", "encounter_duration_confirmation": "The duration of this encounter would be" } \ No newline at end of file