From 539beecc51200417059258faf1c7c5b8e2efb213 Mon Sep 17 00:00:00 2001 From: Suprabath <34211797+suprabathk@users.noreply.github.com> Date: Wed, 6 Sep 2023 08:38:58 +0530 Subject: [PATCH 1/2] Added nav link for bed status in consultation form (#6170) --- src/Components/Facility/ConsultationForm.tsx | 22 +++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Components/Facility/ConsultationForm.tsx b/src/Components/Facility/ConsultationForm.tsx index ed7fd7b57b6..c71c70b162c 100644 --- a/src/Components/Facility/ConsultationForm.tsx +++ b/src/Components/Facility/ConsultationForm.tsx @@ -198,7 +198,8 @@ const consultationFormReducer = (state = initialState, action: FormAction) => { type ConsultationFormSection = | "Consultation Details" | "Diagnosis" - | "Treatment Plan"; + | "Treatment Plan" + | "Bed Status"; export const ConsultationForm = (props: any) => { const { goBack } = useAppHistory(); @@ -223,6 +224,7 @@ export const ConsultationForm = (props: any) => { const [consultationDetailsVisible, consultationDetailsRef] = useVisibility(); const [diagnosisVisible, diagnosisRef] = useVisibility(-300); const [treatmentPlanVisible, treatmentPlanRef] = useVisibility(-300); + const [bedStatusVisible, bedStatusRef] = useVisibility(-300); const [disabledFields, setDisabledFields] = useState([]); const sections = { @@ -241,6 +243,11 @@ export const ConsultationForm = (props: any) => { visible: treatmentPlanVisible, ref: treatmentPlanRef, }, + "Bed Status": { + iconClass: "care-l-bed", + visible: bedStatusVisible, + ref: bedStatusRef, + }, }; useEffect(() => { @@ -248,9 +255,15 @@ export const ConsultationForm = (props: any) => { if (consultationDetailsVisible) return "Consultation Details"; if (diagnosisVisible) return "Diagnosis"; if (treatmentPlanVisible) return "Treatment Plan"; + if (bedStatusVisible) return "Bed Status"; return prev; }); - }, [consultationDetailsVisible, diagnosisVisible, treatmentPlanVisible]); + }, [ + consultationDetailsVisible, + diagnosisVisible, + treatmentPlanVisible, + bedStatusVisible, + ]); useEffect(() => { async function fetchPatientName() { @@ -817,6 +830,9 @@ export const ConsultationForm = (props: any) => { if (state.form.consultation_status === 1) { return null; } + if (!isUpdate && sectionTitle === "Bed Status") { + return null; + } const isCurrent = currentSection === sectionTitle; const section = sections[sectionTitle as ConsultationFormSection]; return ( @@ -1306,7 +1322,7 @@ export const ConsultationForm = (props: any) => { {isUpdate && ( <>
-

Update Bed

+ {sectionTitle("Bed Status")} Date: Wed, 6 Sep 2023 03:10:03 +0000 Subject: [PATCH 2/2] Medicine Administrations: Adds `administered_date` input (#6206) * Add input: `administered_date` to Administer Dialog * add administered_date for bulk administer too * fix cypress --- cypress/e2e/patient_spec/patient_crud.cy.ts | 2 +- .../Form/FormFields/CheckBoxFormField.tsx | 1 + .../Medicine/AdministerMedicine.tsx | 61 ++++++++++--- .../Medicine/MedicineAdministration.tsx | 88 +++++++++++++++---- .../PrescriptionAdministrationsTable.tsx | 2 +- src/Components/Medicine/models.ts | 2 +- 6 files changed, 125 insertions(+), 31 deletions(-) diff --git a/cypress/e2e/patient_spec/patient_crud.cy.ts b/cypress/e2e/patient_spec/patient_crud.cy.ts index ff8ffaefcfc..b9e03851897 100644 --- a/cypress/e2e/patient_spec/patient_crud.cy.ts +++ b/cypress/e2e/patient_spec/patient_crud.cy.ts @@ -28,7 +28,7 @@ describe("Patient Creation with consultation", () => { cy.get("#add-patient-details").should("be.visible"); cy.get("#add-patient-details").click(); cy.get("input[name='facilities']") - .type("cypress facility") + .type("dummy facility") .then(() => { cy.get("[role='option']").first().click(); }); diff --git a/src/Components/Form/FormFields/CheckBoxFormField.tsx b/src/Components/Form/FormFields/CheckBoxFormField.tsx index 90c4513f4b7..f3382d522de 100644 --- a/src/Components/Form/FormFields/CheckBoxFormField.tsx +++ b/src/Components/Form/FormFields/CheckBoxFormField.tsx @@ -14,6 +14,7 @@ export default function CheckBoxFormField(props: FormFieldBaseProps) { name={field.name} checked={field.value} onChange={(e) => field.handleChange(e.target.checked)} + disabled={field.disabled} /> (); const [isLoading, setIsLoading] = useState(false); const [notes, setNotes] = useState(""); + const [isCustomTime, setIsCustomTime] = useState(false); + const [customTime, setCustomTime] = useState( + dayjs().format("YYYY-MM-DDTHH:mm") + ); return ( props.onClose(false)} - // variant="primary" onConfirm={async () => { setIsLoading(true); - const res = await dispatch(props.actions.administer({ notes })); + const res = await dispatch( + props.actions.administer({ + notes, + administered_date: isCustomTime ? customTime : undefined, + }) + ); if (res.status === 201) { Success({ msg: t("medicines_administered") }); } @@ -61,15 +72,43 @@ export default function AdministerMedicine({ prescription, ...props }: Props) { readonly actions={props.actions} /> - setNotes(value)} - errorClassName="hidden" - disabled={isLoading} - /> + +
+ setNotes(value)} + errorClassName="hidden" + disabled={isLoading} + /> +
+ { + setIsCustomTime(value); + if (!value) { + setCustomTime(dayjs().format("YYYY-MM-DDTHH:mm")); + } + }} + errorClassName="hidden" + /> + setCustomTime(value)} + disabled={!isCustomTime} + min={dayjs(prescription.created_date).format("YYYY-MM-DDTHH:mm")} + max={dayjs().format("YYYY-MM-DDTHH:mm")} + /> +
+
); diff --git a/src/Components/Medicine/MedicineAdministration.tsx b/src/Components/Medicine/MedicineAdministration.tsx index 16926b32f7b..5d8347ba5a5 100644 --- a/src/Components/Medicine/MedicineAdministration.tsx +++ b/src/Components/Medicine/MedicineAdministration.tsx @@ -10,6 +10,8 @@ import { useDispatch } from "react-redux"; import { Error, Success } from "../../Utils/Notifications"; import { formatDateTime } from "../../Utils/utils"; import { useTranslation } from "react-i18next"; +import dayjs from "../../Utils/dayjs"; +import TextFormField from "../Form/FormFields/TextFormField"; interface Props { prescriptions: Prescription[]; @@ -24,6 +26,8 @@ export default function MedicineAdministration(props: Props) { const [notes, setNotes] = useState( [] ); + const [isCustomTime, setIsCustomTime] = useState([]); + const [customTime, setCustomTime] = useState([]); const prescriptions = useMemo( () => @@ -36,13 +40,21 @@ export default function MedicineAdministration(props: Props) { useEffect(() => { setShouldAdminister(Array(prescriptions.length).fill(false)); setNotes(Array(prescriptions.length).fill("")); + setIsCustomTime(Array(prescriptions.length).fill(false)); + setCustomTime( + Array(prescriptions.length).fill(dayjs().format("YYYY-MM-DDTHH:mm")) + ); }, [props.prescriptions]); const handleSubmit = () => { const records: MedicineAdministrationRecord[] = []; prescriptions.forEach((prescription, i) => { if (shouldAdminister[i]) { - records.push({ prescription, notes: notes[i] }); + records.push({ + prescription, + notes: notes[i], + administered_date: isCustomTime[i] ? customTime[i] : undefined, + }); } }); @@ -73,7 +85,7 @@ export default function MedicineAdministration(props: Props) { actions={props.action(obj?.id ?? "")} selected={shouldAdminister[index]} > -
+
- - setNotes((notes) => { - const newNotes = [...notes]; - newNotes[index] = event.value; - return newNotes; - }) - } - errorClassName="hidden" - /> +
+ + setNotes((notes) => { + const newNotes = [...notes]; + newNotes[index] = event.value; + return newNotes; + }) + } + errorClassName="hidden" + /> +
+ { + setIsCustomTime((arr) => { + const newArr = [...arr]; + newArr[index] = value; + return newArr; + }); + if (!value) { + setCustomTime((arr) => { + const newArr = [...arr]; + newArr[index] = dayjs().format("YYYY-MM-DDTHH:mm"); + return newArr; + }); + } + }} + errorClassName="hidden" + /> + { + setCustomTime((arr) => { + const newArr = [...arr]; + newArr[index] = value; + return newArr; + }); + }} + disabled={!shouldAdminister[index] || !isCustomTime[index]} + min={dayjs(obj.created_date).format("YYYY-MM-DDTHH:mm")} + max={dayjs().format("YYYY-MM-DDTHH:mm")} + /> +
+
))} diff --git a/src/Components/Medicine/PrescriptionAdministrationsTable.tsx b/src/Components/Medicine/PrescriptionAdministrationsTable.tsx index c60d531baa3..81282126d7c 100644 --- a/src/Components/Medicine/PrescriptionAdministrationsTable.tsx +++ b/src/Components/Medicine/PrescriptionAdministrationsTable.tsx @@ -85,7 +85,7 @@ export default function PrescriptionAdministrationsTable({ {state?.prescriptions && ( diff --git a/src/Components/Medicine/models.ts b/src/Components/Medicine/models.ts index cb48e9cc174..62aea46b6d2 100644 --- a/src/Components/Medicine/models.ts +++ b/src/Components/Medicine/models.ts @@ -53,8 +53,8 @@ export type MedicineAdministrationRecord = { readonly id?: string; readonly prescription?: Prescription; notes: string; + administered_date?: string; readonly administered_by?: PerformedByModel; - readonly administered_date?: string; readonly created_date?: string; readonly modified_date?: string; };