Skip to content

Commit

Permalink
Refactor discharge_reason data type to Integer
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashesh3 committed Dec 7, 2023
1 parent 745d4f8 commit 5693149
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 36 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 LINES_CATHETER_CHOICES: Array<OptionsType> = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,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.discharge_reason ===
DISCHARGE_REASONS.find((i) => i.text == "Recovered")?.id &&
"lg:col-span-2"
}`}
>
Expand All @@ -214,7 +215,9 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => {
)?.text ?? "--"}
</span>
</div>
{props.consultationData.discharge_reason === "REF" && (
{props.consultationData.discharge_reason ===
DISCHARGE_REASONS.find((i) => i.text == "Referred")
?.id && (
<div>
Referred Facility {" - "}
<span className="font-semibold">
Expand All @@ -224,7 +227,9 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => {
</span>
</div>
)}
{props.consultationData.discharge_reason === "REC" && (
{props.consultationData.discharge_reason ===
DISCHARGE_REASONS.find((i) => i.text == "Recovered")
?.id && (
<div className="grid gap-4">
<div>
Discharge Date {" - "}
Expand Down Expand Up @@ -259,7 +264,9 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => {
</div>
</div>
)}
{props.consultationData.discharge_reason === "EXP" && (
{props.consultationData.discharge_reason ===
DISCHARGE_REASONS.find((i) => i.text == "Expired")
?.id && (
<div className="grid gap-4">
<div>
Date of Death {" - "}
Expand All @@ -286,8 +293,8 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => {
</div>
</div>
)}
{["REF", "LAMA"].includes(
props.consultationData.discharge_reason ?? ""
{[2, 4].includes(
props.consultationData.discharge_reason ?? 0
) && (
<div className="grid gap-4">
<div>
Expand Down
10 changes: 6 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,
PATIENT_CATEGORIES,
REVIEW_AT_CHOICES,
TELEMEDICINE_ACTIONS,
Expand Down Expand Up @@ -120,7 +121,7 @@ type FormDetails = {
weight: string;
height: string;
bed: BedModel | null;
discharge_reason: string;
discharge_reason: number | null;
cause_of_death: string;
death_datetime: string;
death_confirmed_doctor: string;
Expand Down Expand Up @@ -170,7 +171,7 @@ const initForm: FormDetails = {
weight: "",
height: "",
bed: null,
discharge_reason: "",
discharge_reason: null,
cause_of_death: "",
death_datetime: "",
death_confirmed_doctor: "",
Expand Down Expand Up @@ -396,7 +397,7 @@ export const ConsultationForm = (props: any) => {
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 || "",
discharge_reason: res.data?.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 @@ -648,7 +649,8 @@ export const ConsultationForm = (props: any) => {
const dischargeResponse = await dispatchAction(
dischargePatient(
{
discharge_reason: "EXP",
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
43 changes: 27 additions & 16 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;
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;
discharge_reason?: number | null;
discharge_notes?: string;
discharge_date?: string;
death_datetime?: string;
Expand All @@ -54,7 +54,7 @@ const DischargeModal = ({
onClose();
window.location.reload();
},
discharge_reason = "",
discharge_reason = null,
discharge_notes = "",
discharge_date = dayjs().format("YYYY-MM-DDTHH:mm"),
death_datetime = dayjs().format("YYYY-MM-DDTHH:mm"),
Expand Down Expand Up @@ -123,8 +123,9 @@ const DischargeModal = ({
}

if (
preDischargeForm.discharge_reason == "EXP" &&
!preDischargeForm.discharge_notes.trim()
(preDischargeForm.discharge_reason ==
DISCHARGE_REASONS.find((i) => i.text == "Expired")?.id,
!preDischargeForm.discharge_notes.trim())
) {
setErrors({
...errors,
Expand Down Expand Up @@ -212,7 +213,8 @@ const DischargeModal = ({
}
error={errors?.discharge_reason}
/>
{preDischargeForm.discharge_reason === "REF" && (
{preDischargeForm.discharge_reason ===
DISCHARGE_REASONS.find((i) => i.text == "Referred")?.id && (
<>
<FieldLabel>Referred to</FieldLabel>
<FacilitySelect
Expand All @@ -230,12 +232,15 @@ const DischargeModal = ({
</>
)}
<TextAreaFormField
required={preDischargeForm.discharge_reason == "EXP"}
required={
preDischargeForm.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.discharge_reason ?? 0] ?? "Notes"
}
name="discharge_notes"
value={preDischargeForm.discharge_notes}
Expand All @@ -249,19 +254,22 @@ const DischargeModal = ({
/>
<TextFormField
name={
preDischargeForm.discharge_reason === "EXP"
preDischargeForm.discharge_reason ===
DISCHARGE_REASONS.find((i) => i.text == "Expired")?.id
? "death_datetime"
: "discharge_date"
}
label={
preDischargeForm.discharge_reason === "EXP"
preDischargeForm.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.discharge_reason ===
DISCHARGE_REASONS.find((i) => i.text == "Expired")?.id
? "death_datetime"
: "discharge_date"
]
Expand All @@ -280,13 +288,15 @@ const DischargeModal = ({
).format("YYYY-MM-DDTHH:mm")}
max={dayjs().format("YYYY-MM-DDTHH:mm")}
error={
preDischargeForm.discharge_reason === "EXP"
preDischargeForm.discharge_reason ===
DISCHARGE_REASONS.find((i) => i.text == "Expired")?.id
? errors?.death_datetime
: errors?.discharge_date
}
/>

{preDischargeForm.discharge_reason === "REC" && (
{preDischargeForm.discharge_reason ===
DISCHARGE_REASONS.find((i) => i.text == "Recovered")?.id && (
<>
<div className="mb-4">
<FieldLabel>Discharge Prescription Medications</FieldLabel>
Expand All @@ -298,7 +308,8 @@ const DischargeModal = ({
</div>
</>
)}
{preDischargeForm.discharge_reason === "EXP" && (
{preDischargeForm.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 @@ -100,7 +100,7 @@ export interface ConsultationModel {
category?: PatientCategory;
created_date?: string;
discharge_date?: string;
discharge_reason?: string;
discharge_reason?: number;
discharge_prescription?: NormalPrescription;
discharge_prn_prescription?: PRNPrescription;
discharge_notes?: string;
Expand Down
9 changes: 7 additions & 2 deletions src/Components/Patient/PatientHome.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { navigate } from "raviger";
import { lazy, useCallback, useEffect, useState } from "react";
import { useDispatch } from "react-redux";
import { GENDER_TYPES, SAMPLE_TEST_STATUS } from "../../Common/constants";
import {
DISCHARGE_REASONS,
GENDER_TYPES,
SAMPLE_TEST_STATUS,
} from "../../Common/constants";
import { statusType, useAbortableEffect } from "../../Common/utils";
import {
getConsultationList,
Expand Down Expand Up @@ -757,7 +761,8 @@ export const PatientHome = (props: any) => {
</div>
</div>
<div className="py-2">
{patientData.last_consultation?.discharge_reason === "EXP" && (
{patientData.last_consultation?.discharge_reason ===
DISCHARGE_REASONS.find((i) => i.text == "Expired")?.id && (
<div>
<ButtonV2
className="mt-6 w-full"
Expand Down
6 changes: 4 additions & 2 deletions src/Components/Patient/PatientInfoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ export default function PatientInfoCard(props: {
: consultation?.created_date
)}
,
{consultation?.discharge_reason === "EXP" ? (
{consultation?.discharge_reason ===
DISCHARGE_REASONS.find((i) => i.text == "Expired")?.id ? (
<span>
{" "}
Expired on {formatDate(consultation?.death_datetime)}
Expand Down Expand Up @@ -354,7 +355,8 @@ export default function PatientInfoCard(props: {
? "OP file closed"
: "UNKNOWN"}
</span>
) : consultation?.discharge_reason === "EXP" ? (
) : consultation?.discharge_reason ===
DISCHARGE_REASONS.find((i) => i.text == "Expired")?.id ? (
<span className="text-red-600">EXPIRED</span>
) : (
DISCHARGE_REASONS.find(
Expand Down
5 changes: 4 additions & 1 deletion src/Components/Shifting/ShiftDetailsUpdate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as Notification from "../../Utils/Notifications.js";

import {
BREATHLESSNESS_LEVEL,
DISCHARGE_REASONS,
FACILITY_TYPES,
PATIENT_CATEGORIES,
SHIFTING_CHOICES_PEACETIME,
Expand Down Expand Up @@ -282,7 +283,9 @@ export const ShiftDetailsUpdate = (props: patientShiftProps) => {
show={showDischargeModal}
onClose={() => setShowDischargeModal(false)}
consultationData={consultationData}
discharge_reason="EXP"
discharge_reason={
DISCHARGE_REASONS.find((i) => i.text == "Expired")?.id
}
afterSubmit={() => {
handleSubmit(true);
}}
Expand Down

0 comments on commit 5693149

Please sign in to comment.