Skip to content

Commit

Permalink
Refactor discharge form field labels and add
Browse files Browse the repository at this point in the history
conditional rendering for death-related fields
  • Loading branch information
rithviknishad committed Nov 30, 2023
1 parent c2ea000 commit a079bb6
Showing 1 changed file with 61 additions and 94 deletions.
155 changes: 61 additions & 94 deletions src/Components/Facility/DischargeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,10 @@ const DischargeModal = ({
<TextAreaFormField
required={preDischargeForm.discharge_reason == "EXP"}
label={
preDischargeForm.discharge_reason == "EXP"
? "Cause of death"
: preDischargeForm.discharge_reason === "REC"
? "Discharged Advice"
: "Notes"
{
EXP: "Cause of death",
REC: "Discharged Advice",
}[preDischargeForm.discharge_reason] ?? "Notes"
}
name="discharge_notes"
value={preDischargeForm.discharge_notes}
Expand All @@ -248,31 +247,47 @@ const DischargeModal = ({
}
error={errors?.discharge_notes}
/>
{preDischargeForm.discharge_reason === "REC" && (
<div>
<TextFormField
label="Date and Time of Discharge"
name="discharge_date"
required
type="datetime-local"
value={dayjs(preDischargeForm?.discharge_date).format(
"YYYY-MM-DDTHH:mm"
)}
min={dayjs(
consultationData?.admission_date ??
consultationData?.created_date
).format("YYYY-MM-DDTHH:mm")}
max={dayjs().format("YYYY-MM-DDTHH:mm")}
onChange={(e) => {
setPreDischargeForm((form) => {
return {
...form,
discharge_date: e.value,
};
});
}}
/>
<TextFormField
name={
preDischargeForm.discharge_reason === "EXP"
? "death_datetime"
: "discharge_date"
}
label={
preDischargeForm.discharge_reason === "EXP"
? "Date of Death"
: "Date and Time of Discharge"
}
type="datetime-local"
value={
preDischargeForm[
preDischargeForm.discharge_reason === "EXP"
? "death_datetime"
: "discharge_date"
]
}
onChange={(e) => {
const updates: Record<string, string | undefined> = {
discharge_date: undefined,
death_datetime: undefined,
};
updates[e.name] = e.value;
setPreDischargeForm((form) => ({ ...form, ...updates }));
}}
required
min={dayjs(
consultationData?.admission_date ?? consultationData?.created_date
).format("YYYY-MM-DDTHH:mm")}
max={dayjs().format("YYYY-MM-DDTHH:mm")}
error={
preDischargeForm.discharge_reason === "EXP"
? errors?.death_datetime
: errors?.discharge_date
}
/>

{preDischargeForm.discharge_reason !== "EXP" ? (
<>
<div className="mb-4">
<FieldLabel>Discharge Prescription Medications</FieldLabel>
<PrescriptionBuilder prescription_type="DISCHARGE" />
Expand All @@ -281,71 +296,23 @@ const DischargeModal = ({
<FieldLabel>Discharge PRN Prescriptions</FieldLabel>
<PrescriptionBuilder prescription_type="DISCHARGE" is_prn />
</div>
</div>
)}
{preDischargeForm.discharge_reason === "EXP" && (
<div>
<TextFormField
name="death_datetime"
label="Death Date and Time"
type="datetime-local"
value={preDischargeForm.death_datetime}
onChange={(e) => {
setPreDischargeForm((form) => {
return {
...form,
death_datetime: e.value,
};
});
}}
required
min={dayjs(consultationData?.admission_date).format(
"YYYY-MM-DDTHH:mm"
)}
max={dayjs().format("YYYY-MM-DDTHH:mm")}
/>
<TextFormField
name="death_confirmed_by"
label="Confirmed By"
value={preDischargeForm.death_confirmed_doctor ?? ""}
onChange={(e) => {
setPreDischargeForm((form) => {
return {
...form,
death_confirmed_doctor: e.value,
};
});
}}
required
placeholder="Attending Doctor's Name and Designation"
/>
</div>
)}
{["REF", "LAMA"].includes(preDischargeForm.discharge_reason) && (
<div>
<TextFormField
label="Date and Time of Discharge"
name="discharge_date"
required
type="datetime-local"
value={dayjs(preDischargeForm?.discharge_date).format(
"YYYY-MM-DDTHH:mm"
)}
min={dayjs(
consultationData?.admission_date ??
consultationData?.created_date
).format("YYYY-MM-DDTHH:mm")}
max={dayjs().format("YYYY-MM-DDTHH:mm")}
onChange={(e) => {
setPreDischargeForm((form) => {
return {
...form,
discharge_date: e.value,
};
});
}}
/>
</div>
</>
) : (
<TextFormField
name="death_confirmed_by"
label="Confirmed By"
value={preDischargeForm.death_confirmed_doctor ?? ""}
onChange={(e) => {
setPreDischargeForm((form) => {
return {
...form,
death_confirmed_doctor: e.value,
};
});
}}
required
placeholder="Attending Doctor's Name and Designation"
/>
)}
</div>

Expand Down

0 comments on commit a079bb6

Please sign in to comment.