Skip to content

Commit

Permalink
Refactor discharge_reason data type to Integer (#6807)
Browse files Browse the repository at this point in the history
* Refactor discharge_reason data type to Integer

* Update discharge_reason to new_discharge_reason

* Revert API target in vite.config.ts

* Fix discharge reason and discharge notes validation
  • Loading branch information
Ashesh3 authored Jan 11, 2024
1 parent 901f619 commit f62ea5d
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 60 deletions.
8 changes: 4 additions & 4 deletions src/Common/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,10 @@ export const SYMPTOM_CHOICES = [
];

export const DISCHARGE_REASONS = [
{ id: "REC", text: "Recovered" },
{ id: "EXP", text: "Expired" },
{ id: "REF", text: "Referred" },
{ id: "LAMA", text: "LAMA" },
{ id: 1, text: "Recovered" },
{ id: 2, text: "Referred" },
{ id: 3, text: "Expired" },
{ id: 4, text: "LAMA" },
];

export const CONSCIOUSNESS_LEVEL = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => {
{props.consultationData.discharge_date && (
<div
className={`gap-4 overflow-hidden rounded-lg bg-white shadow ${
props.consultationData.discharge_reason === "REC" &&
props.consultationData.new_discharge_reason ===
DISCHARGE_REASONS.find((i) => i.text == "Recovered")?.id &&
"lg:col-span-2"
}`}
>
Expand All @@ -190,11 +191,13 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => {
<span className="font-semibold">
{DISCHARGE_REASONS.find(
(d) =>
d.id === props.consultationData.discharge_reason
d.id === props.consultationData.new_discharge_reason
)?.text ?? "--"}
</span>
</div>
{props.consultationData.discharge_reason === "REF" && (
{props.consultationData.new_discharge_reason ===
DISCHARGE_REASONS.find((i) => i.text == "Referred")
?.id && (
<div>
Referred Facility {" - "}
<span className="font-semibold">
Expand All @@ -204,7 +207,9 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => {
</span>
</div>
)}
{props.consultationData.discharge_reason === "REC" && (
{props.consultationData.new_discharge_reason ===
DISCHARGE_REASONS.find((i) => i.text == "Recovered")
?.id && (
<div className="grid gap-4">
<div>
Discharge Date {" - "}
Expand Down Expand Up @@ -239,7 +244,9 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => {
</div>
</div>
)}
{props.consultationData.discharge_reason === "EXP" && (
{props.consultationData.new_discharge_reason ===
DISCHARGE_REASONS.find((i) => i.text == "Expired")
?.id && (
<div className="grid gap-4">
<div>
Date of Death {" - "}
Expand All @@ -266,8 +273,8 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => {
</div>
</div>
)}
{["REF", "LAMA"].includes(
props.consultationData.discharge_reason ?? ""
{[2, 4].includes(
props.consultationData.new_discharge_reason ?? 0
) && (
<div className="grid gap-4">
<div>
Expand Down
11 changes: 7 additions & 4 deletions src/Components/Facility/ConsultationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as Notification from "../../Utils/Notifications.js";
import { BedModel, FacilityModel } from "./models";
import {
CONSULTATION_SUGGESTION,
DISCHARGE_REASONS,
ConsultationSuggestionValue,
PATIENT_CATEGORIES,
REVIEW_AT_CHOICES,
Expand Down Expand Up @@ -121,7 +122,7 @@ type FormDetails = {
weight: string;
height: string;
bed: BedModel | null;
discharge_reason: string;
new_discharge_reason: number | null;
cause_of_death: string;
death_datetime: string;
death_confirmed_doctor: string;
Expand Down Expand Up @@ -171,7 +172,7 @@ const initForm: FormDetails = {
weight: "",
height: "",
bed: null,
discharge_reason: "",
new_discharge_reason: null,
cause_of_death: "",
death_datetime: "",
death_confirmed_doctor: "",
Expand Down Expand Up @@ -402,7 +403,7 @@ export const ConsultationForm = ({ facilityId, patientId, id }: Props) => {
weight: res.data.weight ? res.data.weight : "",
height: res.data.height ? res.data.height : "",
bed: res.data?.current_bed?.bed_object || null,
discharge_reason: res.data?.discharge_reason || "",
new_discharge_reason: res.data?.new_discharge_reason || null,
cause_of_death: res.data?.discharge_notes || "",
death_datetime: res.data?.death_datetime || "",
death_confirmed_doctor: res.data?.death_confirmed_doctor || "",
Expand Down Expand Up @@ -653,7 +654,9 @@ export const ConsultationForm = ({ facilityId, patientId, id }: Props) => {
const dischargeResponse = await dispatchAction(
dischargePatient(
{
discharge_reason: "EXP",
new_discharge_reason: DISCHARGE_REASONS.find(
(i) => i.text === "Expired"
)?.id,
discharge_notes: cause_of_death,
death_datetime: death_datetime,
death_confirmed_doctor: death_confirmed_doctor,
Expand Down
55 changes: 33 additions & 22 deletions src/Components/Facility/DischargeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { FacilityModel } from "./models";
import dayjs from "../../Utils/dayjs";

interface PreDischargeFormInterface {
discharge_reason: string;
new_discharge_reason: number | null;
discharge_notes: string;
discharge_date?: string;
death_datetime?: string;
Expand All @@ -40,7 +40,7 @@ interface IProps {
onClose: () => void;
consultationData: ConsultationModel;
afterSubmit?: () => void;
discharge_reason?: string;
new_discharge_reason?: number | null;
discharge_notes?: string;
discharge_date?: string;
death_datetime?: string;
Expand All @@ -51,7 +51,7 @@ const DischargeModal = ({
onClose,
consultationData,
afterSubmit,
discharge_reason = "",
new_discharge_reason = null,
discharge_notes = "",
discharge_date = dayjs().format("YYYY-MM-DDTHH:mm"),
death_datetime = dayjs().format("YYYY-MM-DDTHH:mm"),
Expand All @@ -60,7 +60,7 @@ const DischargeModal = ({
const dispatch: any = useDispatch();
const [preDischargeForm, setPreDischargeForm] =
useState<PreDischargeFormInterface>({
discharge_reason,
new_discharge_reason,
discharge_notes,
discharge_date,
death_datetime,
Expand Down Expand Up @@ -110,17 +110,18 @@ const DischargeModal = ({

const handlePatientDischarge = async (value: boolean) => {
setIsSendingDischargeApi(true);
if (!preDischargeForm.discharge_reason) {
if (!preDischargeForm.new_discharge_reason) {
setErrors({
...errors,
discharge_reason: "Please select a reason for discharge",
new_discharge_reason: "Please select a reason for discharge",
});
setIsSendingDischargeApi(false);
return;
}

if (
preDischargeForm.discharge_reason == "EXP" &&
preDischargeForm.new_discharge_reason ==
DISCHARGE_REASONS.find((i) => i.text == "Expired")?.id &&
!preDischargeForm.discharge_notes.trim()
) {
setErrors({
Expand Down Expand Up @@ -196,20 +197,21 @@ const DischargeModal = ({
label="Reason"
name="discharge_reason"
id="discharge_reason"
value={preDischargeForm.discharge_reason}
disabled={!!discharge_reason}
value={preDischargeForm.new_discharge_reason}
disabled={!!new_discharge_reason}
options={DISCHARGE_REASONS}
optionValue={({ id }) => id}
optionLabel={({ text }) => text}
onChange={(e) =>
setPreDischargeForm((prev) => ({
...prev,
discharge_reason: e.value,
new_discharge_reason: e.value,
}))
}
error={errors?.discharge_reason}
error={errors?.new_discharge_reason}
/>
{preDischargeForm.discharge_reason === "REF" && (
{preDischargeForm.new_discharge_reason ===
DISCHARGE_REASONS.find((i) => i.text == "Referred")?.id && (
<>
<FieldLabel>Referred to</FieldLabel>
<FacilitySelect
Expand All @@ -227,12 +229,15 @@ const DischargeModal = ({
</>
)}
<TextAreaFormField
required={preDischargeForm.discharge_reason == "EXP"}
required={
preDischargeForm.new_discharge_reason ==
DISCHARGE_REASONS.find((i) => i.text == "Expired")?.id
}
label={
{
EXP: "Cause of death",
REC: "Discharged Advice",
}[preDischargeForm.discharge_reason] ?? "Notes"
"3": "Cause of death",
"1": "Discharged Advice",
}[preDischargeForm.new_discharge_reason ?? 0] ?? "Notes"
}
name="discharge_notes"
value={preDischargeForm.discharge_notes}
Expand All @@ -246,19 +251,22 @@ const DischargeModal = ({
/>
<TextFormField
name={
preDischargeForm.discharge_reason === "EXP"
preDischargeForm.new_discharge_reason ===
DISCHARGE_REASONS.find((i) => i.text == "Expired")?.id
? "death_datetime"
: "discharge_date"
}
label={
preDischargeForm.discharge_reason === "EXP"
preDischargeForm.new_discharge_reason ===
DISCHARGE_REASONS.find((i) => i.text == "Expired")?.id
? "Date of Death"
: "Date and Time of Discharge"
}
type="datetime-local"
value={
preDischargeForm[
preDischargeForm.discharge_reason === "EXP"
preDischargeForm.new_discharge_reason ===
DISCHARGE_REASONS.find((i) => i.text == "Expired")?.id
? "death_datetime"
: "discharge_date"
]
Expand All @@ -277,13 +285,15 @@ const DischargeModal = ({
)}
max={dayjs().format("YYYY-MM-DDTHH:mm")}
error={
preDischargeForm.discharge_reason === "EXP"
preDischargeForm.new_discharge_reason ===
DISCHARGE_REASONS.find((i) => i.text == "Expired")?.id
? errors?.death_datetime
: errors?.discharge_date
}
/>

{preDischargeForm.discharge_reason === "REC" && (
{preDischargeForm.new_discharge_reason ===
DISCHARGE_REASONS.find((i) => i.text == "Recovered")?.id && (
<>
<div className="mb-4">
<FieldLabel>Discharge Prescription Medications</FieldLabel>
Expand All @@ -295,7 +305,8 @@ const DischargeModal = ({
</div>
</>
)}
{preDischargeForm.discharge_reason === "EXP" && (
{preDischargeForm.new_discharge_reason ===
DISCHARGE_REASONS.find((i) => i.text == "Expired")?.id && (
<TextFormField
name="death_confirmed_by"
label="Confirmed By"
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Facility/models.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export interface ConsultationModel {
category?: PatientCategory;
created_date?: string;
discharge_date?: string;
discharge_reason?: string;
new_discharge_reason?: number;
discharge_prescription?: NormalPrescription;
discharge_prn_prescription?: PRNPrescription;
discharge_notes?: string;
Expand Down
15 changes: 8 additions & 7 deletions src/Components/Patient/ManagePatients.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ export const PatientManager = () => {
};

const tabValue =
qParams.last_consultation_discharge_reason || qParams.is_active === "False"
qParams.last_consultation__new_discharge_reason ||
qParams.is_active === "False"
? 1
: 0;

Expand All @@ -163,7 +164,7 @@ export const PatientManager = () => {
name: qParams.name || undefined,
patient_no: qParams.patient_no || undefined,
is_active:
!qParams.last_consultation_discharge_reason &&
!qParams.last_consultation__new_discharge_reason &&
(qParams.is_active || "True"),
disease_status: qParams.disease_status || undefined,
phone_number: qParams.phone_number
Expand Down Expand Up @@ -204,8 +205,8 @@ export const PatientManager = () => {
qParams.last_consultation_discharge_date_after || undefined,
last_consultation_admitted_bed_type_list:
qParams.last_consultation_admitted_bed_type_list || undefined,
last_consultation_discharge_reason:
qParams.last_consultation_discharge_reason || undefined,
last_consultation__new_discharge_reason:
qParams.last_consultation__new_discharge_reason || undefined,
last_consultation_current_bed__location:
qParams.last_consultation_current_bed__location || undefined,
srf_id: qParams.srf_id || undefined,
Expand Down Expand Up @@ -352,7 +353,7 @@ export const PatientManager = () => {
qParams.age_max,
qParams.age_min,
qParams.last_consultation_admitted_bed_type_list,
qParams.last_consultation_discharge_reason,
qParams.last_consultation__new_discharge_reason,
qParams.last_consultation_current_bed__location,
qParams.facility,
qParams.facility_type,
Expand Down Expand Up @@ -1022,10 +1023,10 @@ export const PatientManager = () => {
},
value(
"Discharge Reason",
"last_consultation_discharge_reason",
"last_consultation__new_discharge_reason",
parseOptionId(
DISCHARGE_REASONS,
qParams.last_consultation_discharge_reason
qParams.last_consultation__new_discharge_reason
) || ""
),
]}
Expand Down
16 changes: 8 additions & 8 deletions src/Components/Patient/PatientFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ export default function PatientFilter(props: any) {
: [],
last_consultation_current_bed__location:
filter.last_consultation_current_bed__location || "",
last_consultation_discharge_reason:
filter.last_consultation_discharge_reason || null,
last_consultation__new_discharge_reason:
filter.last_consultation__new_discharge_reason || null,
srf_id: filter.srf_id || null,
number_of_doses: filter.number_of_doses || null,
covin_id: filter.covin_id || null,
Expand Down Expand Up @@ -241,7 +241,7 @@ export default function PatientFilter(props: any) {
last_consultation_discharge_date_before,
last_consultation_discharge_date_after,
last_consultation_admitted_bed_type_list,
last_consultation_discharge_reason,
last_consultation__new_discharge_reason,
last_consultation_current_bed__location,
number_of_doses,
covin_id,
Expand Down Expand Up @@ -298,8 +298,8 @@ export default function PatientFilter(props: any) {
age_max: age_max || "",
last_consultation_admitted_bed_type_list:
last_consultation_admitted_bed_type_list || [],
last_consultation_discharge_reason:
last_consultation_discharge_reason || "",
last_consultation__new_discharge_reason:
last_consultation__new_discharge_reason || "",
srf_id: srf_id || "",
number_of_doses: number_of_doses || "",
covin_id: covin_id || "",
Expand Down Expand Up @@ -424,16 +424,16 @@ export default function PatientFilter(props: any) {
<div className="w-full flex-none" id="discharge-reason-select">
<FieldLabel className="text-sm">Discharge Reason</FieldLabel>
<SelectMenuV2
id="last_consultation_discharge_reason"
id="last_consultation__new_discharge_reason"
placeholder="Select discharge reason"
options={DISCHARGE_REASONS}
value={filterState.last_consultation_discharge_reason}
value={filterState.last_consultation__new_discharge_reason}
optionValue={(o) => o.id}
optionLabel={(o) => o.text}
onChange={(o) =>
setFilterState({
...filterState,
last_consultation_discharge_reason: o,
last_consultation__new_discharge_reason: o,
})
}
/>
Expand Down
Loading

0 comments on commit f62ea5d

Please sign in to comment.