From e5ecbe4f9b6a6bb082bdf92ab4320f14733ef9ee Mon Sep 17 00:00:00 2001 From: Shivank Kacker Date: Tue, 21 May 2024 12:25:11 +0530 Subject: [PATCH] . --- src/Components/Facility/ConsultationForm.tsx | 216 +--------------- src/Components/Facility/models.tsx | 47 ++-- .../Patient/PatientConsentRecords.tsx | 237 ++++++++++++++++++ src/Components/Patient/PatientInfoCard.tsx | 136 +++++----- src/Routers/routes/ConsultationRoutes.tsx | 4 + 5 files changed, 348 insertions(+), 292 deletions(-) create mode 100644 src/Components/Patient/PatientConsentRecords.tsx diff --git a/src/Components/Facility/ConsultationForm.tsx b/src/Components/Facility/ConsultationForm.tsx index ba248b8db6f..8ea9a2a7dc6 100644 --- a/src/Components/Facility/ConsultationForm.tsx +++ b/src/Components/Facility/ConsultationForm.tsx @@ -8,8 +8,6 @@ import { PATIENT_CATEGORIES, REVIEW_AT_CHOICES, TELEMEDICINE_ACTIONS, - CONSENT_TYPE_CHOICES, - CONSENT_PATIENT_CODE_STATUS_CHOICES, } from "../../Common/constants"; import { Cancel, Submit } from "../Common/components/ButtonV2"; import { DraftSection, useAutoSaveReducer } from "../../Utils/AutoSave"; @@ -71,13 +69,6 @@ const PageTitle = lazy(() => import("../Common/PageTitle")); type BooleanStrings = "true" | "false"; -export type ConsentRecord = { - id: string; - type: (typeof CONSENT_TYPE_CHOICES)[number]["id"]; - patient_code_status?: (typeof CONSENT_PATIENT_CODE_STATUS_CHOICES)[number]["id"]; - deleted?: boolean; -}; - type FormDetails = { symptoms: number[]; other_symptoms: string; @@ -126,7 +117,6 @@ type FormDetails = { death_confirmed_doctor: string; InvestigationAdvice: InvestigationType[]; procedures: ProcedureType[]; - consent_records: ConsentRecord[]; }; const initForm: FormDetails = { @@ -177,7 +167,6 @@ const initForm: FormDetails = { death_confirmed_doctor: "", InvestigationAdvice: [], procedures: [], - consent_records: [], }; const initError = Object.assign( @@ -228,7 +217,6 @@ type ConsultationFormSection = | "Consultation Details" | "Diagnosis" | "Treatment Plan" - | "Consent Records" | "Bed Status"; type Props = { @@ -261,14 +249,9 @@ export const ConsultationForm = ({ facilityId, patientId, id }: Props) => { const [diagnosisVisible, diagnosisRef] = useVisibility(-300); const [treatmentPlanVisible, treatmentPlanRef] = useVisibility(-300); const [bedStatusVisible, bedStatusRef] = useVisibility(-300); - const [consentRecordsVisible, consentRecordsRef] = useVisibility(-300); + const [disabledFields, setDisabledFields] = useState([]); - const [collapsedConsentRecords, setCollapsedConsentRecords] = useState< - number[] - >([]); - const [showDeleteConsent, setShowDeleteConsent] = useState( - null, - ); + const { min_encounter_date } = useConfig(); @@ -288,11 +271,6 @@ export const ConsultationForm = ({ facilityId, patientId, id }: Props) => { visible: treatmentPlanVisible, ref: treatmentPlanRef, }, - "Consent Records": { - iconClass: "l-file-alt", - visible: consentRecordsVisible, - ref: consentRecordsRef, - }, "Bed Status": { iconClass: "l-bed", visible: bedStatusVisible, @@ -305,7 +283,6 @@ export const ConsultationForm = ({ facilityId, patientId, id }: Props) => { if (consultationDetailsVisible) return "Consultation Details"; if (diagnosisVisible) return "Diagnosis"; if (treatmentPlanVisible) return "Treatment Plan"; - if (consentRecordsVisible) return "Consent Records"; if (bedStatusVisible) return "Bed Status"; return prev; }); @@ -313,7 +290,6 @@ export const ConsultationForm = ({ facilityId, patientId, id }: Props) => { consultationDetailsVisible, diagnosisVisible, treatmentPlanVisible, - consentRecordsVisible, bedStatusVisible, ]); @@ -408,7 +384,7 @@ export const ConsultationForm = ({ facilityId, patientId, id }: Props) => { admitted_to: data.admitted_to ? data.admitted_to : "", category: data.category ? PATIENT_CATEGORIES.find((i) => i.text === data.category)?.id ?? - "" + "" : "", patient_no: data.patient_no ?? "", OPconsultation: data.consultation_notes, @@ -738,12 +714,12 @@ export const ConsultationForm = ({ facilityId, patientId, id }: Props) => { : undefined, referred_from_facility: state.form.route_to_facility === 20 && - !state.form.referred_from_facility_external + !state.form.referred_from_facility_external ? state.form.referred_from_facility : undefined, referred_from_facility_external: state.form.route_to_facility === 20 && - !state.form.referred_from_facility + !state.form.referred_from_facility ? state.form.referred_from_facility_external : undefined, referred_by_external: @@ -771,7 +747,6 @@ export const ConsultationForm = ({ facilityId, patientId, id }: Props) => { height: Number(state.form.height), bed: bed && bed instanceof Array ? bed[0]?.id : bed?.id, patient_no: state.form.patient_no || null, - consent_records: state.form.consent_records || [], }; const { data: obj } = await request( @@ -919,64 +894,6 @@ export const ConsultationForm = ({ facilityId, patientId, id }: Props) => { }; }; - const handleConsentTypeChange: FieldChangeEventHandler = async ( - event, - ) => { - if (!id) return; - const consentRecords = [...state.form.consent_records]; - if ( - consentRecords - .filter((cr) => cr.deleted !== true) - .map((cr) => cr.type) - .includes(event.value) - ) { - return; - } else { - const randomId = "consent-" + new Date().getTime().toString(); - const newRecords = [ - ...consentRecords, - { id: randomId, type: event.value }, - ]; - await request(routes.partialUpdateConsultation, { - pathParams: { id }, - body: { consent_records: newRecords }, - }); - dispatch({ - type: "set_form", - form: { ...state.form, consent_records: newRecords }, - }); - } - }; - - const handleConsentPCSChange: FieldChangeEventHandler = (event) => { - dispatch({ - type: "set_form", - form: { - ...state.form, - consent_records: state.form.consent_records.map((cr) => - cr.type === 2 ? { ...cr, patient_code_status: event.value } : cr, - ), - }, - }); - }; - - const handleDeleteConsent = async () => { - const consent_id = showDeleteConsent; - if (!consent_id || !id) return; - const newRecords = state.form.consent_records.map((cr) => - cr.id === consent_id ? { ...cr, deleted: true } : cr, - ); - await request(routes.partialUpdateConsultation, { - pathParams: { id }, - body: { consent_records: newRecords }, - }); - dispatch({ - type: "set_form", - form: { ...state.form, consent_records: newRecords }, - }); - setShowDeleteConsent(null); - }; - return (
{ {Object.keys(sections).map((sectionTitle) => { if ( !isUpdate && - ["Bed Status", "Consent Records"].includes(sectionTitle) + ["Bed Status"].includes(sectionTitle) ) { return null; } @@ -1006,9 +923,8 @@ export const ConsultationForm = ({ facilityId, patientId, id }: Props) => { const section = sections[sectionTitle as ConsultationFormSection]; return (
- {id && ( - <> -
- {sectionTitle("Consent Records", true)} -
- setShowDeleteConsent(null)} - onConfirm={handleDeleteConsent} - action="Delete" - variant="danger" - description={ - "Are you sure you want to delete this consent record?" - } - title="Delete Consent" - className="w-auto" - /> - - !state.form.consent_records - .filter((r) => r.deleted !== true) - .map((record) => record.type) - .includes(c.id), - )} - /> -
- {state.form.consent_records - .filter((record) => record.deleted !== true) - .map((record, index) => ( -
-
- - -
-
-
- {record.type === 2 && ( - - )} -
- -
-
- ))} -
- - )}
diff --git a/src/Components/Facility/models.tsx b/src/Components/Facility/models.tsx index d61d5a9f129..63a448ae331 100644 --- a/src/Components/Facility/models.tsx +++ b/src/Components/Facility/models.tsx @@ -1,4 +1,6 @@ import { + CONSENT_PATIENT_CODE_STATUS_CHOICES, + CONSENT_TYPE_CHOICES, ConsultationSuggestionValue, DISCHARGE_REASONS, PATIENT_NOTES_THREADS, @@ -12,7 +14,6 @@ import { ConsultationDiagnosis, CreateDiagnosis } from "../Diagnosis/types"; import { NormalPrescription, PRNPrescription } from "../Medicine/models"; import { AssignedToObjectModel, DailyRoundsModel } from "../Patient/models"; import { UserBareMinimum } from "../Users/models"; -import { ConsentRecord } from "./ConsultationForm"; export interface LocalBodyModel { id: number; @@ -101,6 +102,14 @@ export type PatientCategory = | "Abnormal" | "Critical"; + +export type ConsentRecord = { + id: string; + type: (typeof CONSENT_TYPE_CHOICES)[number]["id"]; + patient_code_status?: (typeof CONSENT_PATIENT_CODE_STATUS_CHOICES)[number]["id"]; + deleted?: boolean; +}; + export interface ConsultationModel { encounter_date: string; icu_admission_date?: string; @@ -432,15 +441,15 @@ export type VentilatorPlotRes = { export interface DailyRoundsBody { page?: number; fields: - | ABGPlotsFields[] - | DialysisPlotsFields[] - | NeurologicalTablesFields[] - | NursingPlotFields[] - | NutritionPlotsFields[] - | PainDiagramsFields[] - | PressureSoreDiagramsFields[] - | PrimaryParametersPlotFields[] - | VentilatorPlotFields[]; + | ABGPlotsFields[] + | DialysisPlotsFields[] + | NeurologicalTablesFields[] + | NursingPlotFields[] + | NutritionPlotsFields[] + | PainDiagramsFields[] + | PressureSoreDiagramsFields[] + | PrimaryParametersPlotFields[] + | VentilatorPlotFields[]; } export interface DailyRoundsRes { @@ -448,15 +457,15 @@ export interface DailyRoundsRes { page_size: number; results: { [date: string]: - | PressureSoreDiagramsRes - | ABGPlotsRes - | DialysisPlotsRes - | NeurologicalTablesRes - | NursingPlotRes - | NutritionPlotsRes - | PainDiagramsRes - | PrimaryParametersPlotRes - | VentilatorPlotRes; + | PressureSoreDiagramsRes + | ABGPlotsRes + | DialysisPlotsRes + | NeurologicalTablesRes + | NursingPlotRes + | NutritionPlotsRes + | PainDiagramsRes + | PrimaryParametersPlotRes + | VentilatorPlotRes; }; } diff --git a/src/Components/Patient/PatientConsentRecords.tsx b/src/Components/Patient/PatientConsentRecords.tsx new file mode 100644 index 00000000000..cb0c1fbbbbf --- /dev/null +++ b/src/Components/Patient/PatientConsentRecords.tsx @@ -0,0 +1,237 @@ +import { useState } from "react"; +import { CONSENT_PATIENT_CODE_STATUS_CHOICES, CONSENT_TYPE_CHOICES } from "../../Common/constants"; +import routes from "../../Redux/api"; +import useQuery from "../../Utils/request/useQuery"; +import Page from "../Common/components/Page" +import { FieldChangeEventHandler } from "../Form/FormFields/Utils"; +import { ConsentRecord } from "../Facility/models"; +import request from "../../Utils/request/request"; +import ConfirmDialog from "../Common/ConfirmDialog"; +import { SelectFormField } from "../Form/FormFields/SelectFormField"; +import CareIcon from "../../CAREUI/icons/CareIcon"; +import { FileUpload } from "./FileUpload"; +import { formatDateTime } from "../../Utils/utils"; + +export default function PatientConsentRecords(props: { + facilityId: string, + patientId: string, + consultationId: string, +}) { + + const { facilityId, patientId, consultationId } = props + + const { data: patient, loading: patientLoading, refetch: patientRefresh } = useQuery(routes.getPatient, { + pathParams: { + id: patientId, + }, + }); + const { data: consultation, loading: consultationLoading, refetch } = useQuery( + routes.getConsultation, + { + pathParams: { id: consultationId! }, + onResponse: (data) => { + if (data.data && data.data.consent_records) { + setConsentRecords(data.data.consent_records); + } + } + }, + ); + + const [collapsedConsentRecords, setCollapsedConsentRecords] = useState< + number[] + >([]); + const [showDeleteConsent, setShowDeleteConsent] = useState( + null, + ); + + const [consentRecords, setConsentRecords] = useState(null); + + + const handleConsentTypeChange: FieldChangeEventHandler = async ( + event, + ) => { + if (!consultationId || !consentRecords) return; + if ( + consentRecords + .filter((cr) => cr.deleted !== true) + .map((cr) => cr.type) + .includes(event.value) + ) { + return; + } else { + const randomId = "consent-" + new Date().getTime().toString(); + const newRecords = [ + ...consentRecords, + { id: randomId, type: event.value }, + ]; + await request(routes.partialUpdateConsultation, { + pathParams: { id: consultationId }, + body: { consent_records: newRecords }, + }); + setConsentRecords(newRecords); + } + }; + + const handleConsentPCSChange: FieldChangeEventHandler = (event) => { + if (!consentRecords) return; + setConsentRecords(consentRecords.map((cr) => + cr.type === 2 ? { ...cr, patient_code_status: event.value } : cr, + )); + }; + + const handleDeleteConsent = async () => { + const consent_id = showDeleteConsent; + if (!consent_id || !consultationId || !consentRecords) return; + const newRecords = consentRecords.map((cr) => + cr.id === consent_id ? { ...cr, deleted: true } : cr, + ); + await request(routes.partialUpdateConsultation, { + pathParams: { id: consultationId }, + body: { consent_records: newRecords }, + }); + setConsentRecords(newRecords); + setShowDeleteConsent(null); + }; + + const selectField = (name: string) => { + return { + name, + optionValue: (option: any) => option.id, + optionLabel: (option: any) => option.text, + optionDescription: (option: any) => option.desc, + }; + }; + + return ( + + setShowDeleteConsent(null)} + onConfirm={handleDeleteConsent} + action="Delete" + variant="danger" + description={ + "Are you sure you want to delete this consent record?" + } + title="Delete Consent" + className="w-auto" + /> +
+
+

+ Add New Record +

+ + !consentRecords + ?.filter((r) => r.deleted !== true) + .map((record) => record.type) + .includes(c.id), + )} + /> +
+
+ +
+ {consentRecords + ?.filter((record) => record.deleted !== true) + .map((record, index) => ( +
+
+ + +
+
+
+ {record.type === 2 && ( + + )} +
+ +
+
+ ))} +
+ +
+ ) +} \ No newline at end of file diff --git a/src/Components/Patient/PatientInfoCard.tsx b/src/Components/Patient/PatientInfoCard.tsx index cd99d169544..0549ed61b8e 100644 --- a/src/Components/Patient/PatientInfoCard.tsx +++ b/src/Components/Patient/PatientInfoCard.tsx @@ -171,7 +171,7 @@ export default function PatientInfoCard(props: { className={`w-24 min-w-20 bg-gray-200 ${categoryClass}-profile h-full`} > {consultation?.current_bed && - consultation?.discharge_date === null ? ( + consultation?.discharge_date === null ? (

{ @@ -279,9 +279,8 @@ export default function PatientInfoCard(props: { {consultation?.patient_no && ( - {`${consultation?.suggestion === "A" ? "IP" : "OP"}: ${ - consultation?.patient_no - }`} + {`${consultation?.suggestion === "A" ? "IP" : "OP"}: ${consultation?.patient_no + }`} )} @@ -424,45 +423,45 @@ export default function PatientInfoCard(props: {

{consultation?.diagnoses?.length ? (() => { - const principal_diagnosis = consultation.diagnoses.find( - (diagnosis) => diagnosis.is_principal, - ); - return principal_diagnosis ? ( -
-
- Principal Diagnosis: -
-
- {principal_diagnosis.diagnosis_object?.label ?? "-"}{" "} - - -

- {principal_diagnosis.verification_status} -

-
-
+ const principal_diagnosis = consultation.diagnoses.find( + (diagnosis) => diagnosis.is_principal, + ); + return principal_diagnosis ? ( +
+
+ Principal Diagnosis: +
+
+ {principal_diagnosis.diagnosis_object?.label ?? "-"}{" "} + + +

+ {principal_diagnosis.verification_status} +

+
- ) : null; - })() +
+ ) : null; + })() : null} {(consultation?.treating_physician_object || consultation?.deprecated_verified_by) && ( -
- - {t("treating_doctor")}:{" "} - - {consultation?.treating_physician_object - ? `${consultation?.treating_physician_object.first_name} ${consultation?.treating_physician_object.last_name}` - : consultation?.deprecated_verified_by} - -
- )} +
+ + {t("treating_doctor")}:{" "} + + {consultation?.treating_physician_object + ? `${consultation?.treating_physician_object.first_name} ${consultation?.treating_physician_object.last_name}` + : consultation?.deprecated_verified_by} + +
+ )}
@@ -532,10 +531,10 @@ export default function PatientInfoCard(props: { { close(); navigate( - `/shifting/${ - activeShiftingData[ - activeShiftingData.length - 1 - ].id + `/shifting/${activeShiftingData[ + activeShiftingData.length - 1 + ].id }`, ); }} @@ -832,10 +836,9 @@ export default function PatientInfoCard(props: { {({ close }) => (
{ if (!consultation?.discharge_date) { close(); @@ -846,11 +849,10 @@ export default function PatientInfoCard(props: {

{t("discharge_from_care")}

diff --git a/src/Routers/routes/ConsultationRoutes.tsx b/src/Routers/routes/ConsultationRoutes.tsx index 6dc5fa9c05d..dc76882a397 100644 --- a/src/Routers/routes/ConsultationRoutes.tsx +++ b/src/Routers/routes/ConsultationRoutes.tsx @@ -9,6 +9,7 @@ import { make as CriticalCareRecording } from "../../Components/CriticalCareReco import { ConsultationDetails } from "../../Components/Facility/ConsultationDetails"; import TreatmentSummary from "../../Components/Facility/TreatmentSummary"; import ConsultationDoctorNotes from "../../Components/Facility/ConsultationDoctorNotes"; +import PatientConsentRecords from "../../Components/Patient/PatientConsentRecords"; export default { "/facility/:facilityId/patient/:patientId/consultation": ({ @@ -22,6 +23,9 @@ export default { }: any) => ( ), + "/facility/:facilityId/patient/:patientId/consultation/:id/consent-records": ({ facilityId, patientId, id }: any) => ( + + ), "/facility/:facilityId/patient/:patientId/consultation/:id/files/": ({ facilityId, patientId,