From 27ddcc945e47dfea516ae6d021c35e180afc6f10 Mon Sep 17 00:00:00 2001 From: Shivank Kacker Date: Sun, 9 Jun 2024 04:58:29 +0530 Subject: [PATCH 1/7] Added consent indicators and filters --- src/Common/hooks/useFilters.tsx | 8 +- .../Facility/DischargedPatientsList.tsx | 42 ++++++++- src/Components/Facility/models.tsx | 7 +- src/Components/Patient/ManagePatients.tsx | 89 ++++++++++++++++++- .../Patient/PatientConsentRecords.tsx | 61 +++---------- src/Components/Patient/PatientFilter.tsx | 24 +++++ src/Components/Patient/models.tsx | 2 + 7 files changed, 175 insertions(+), 58 deletions(-) diff --git a/src/Common/hooks/useFilters.tsx b/src/Common/hooks/useFilters.tsx index b86206c4b2..8bedefc317 100644 --- a/src/Common/hooks/useFilters.tsx +++ b/src/Common/hooks/useFilters.tsx @@ -187,13 +187,17 @@ export default function useFilters({ return acc; }, [] as string[]); + const show = activeFilters.length > 0 || children; + return ( -
+
{compiledBadges.map((props) => ( ))} {children} - {(activeFilters.length >= 1 || children) && ( + {show && (
diff --git a/src/Components/Facility/models.tsx b/src/Components/Facility/models.tsx index 74a0d4a0f2..1b8cd966a5 100644 --- a/src/Components/Facility/models.tsx +++ b/src/Components/Facility/models.tsx @@ -12,7 +12,11 @@ import { InvestigationType } from "../Common/prescription-builder/InvestigationB import { ProcedureType } from "../Common/prescription-builder/ProcedureBuilder"; import { ConsultationDiagnosis, CreateDiagnosis } from "../Diagnosis/types"; import { NormalPrescription, PRNPrescription } from "../Medicine/models"; -import { AssignedToObjectModel, DailyRoundsModel } from "../Patient/models"; +import { + AssignedToObjectModel, + DailyRoundsModel, + FileUploadModel, +} from "../Patient/models"; import { EncounterSymptom } from "../Symptoms/types"; import { UserBareMinimum } from "../Users/models"; @@ -105,6 +109,7 @@ export interface PatientConsentModel { patient_code_status: | (typeof CONSENT_PATIENT_CODE_STATUS_CHOICES)[number]["id"] | null; + files: FileUploadModel[] | null; archived: boolean; archived_by?: UserBareMinimum; archived_date: string; diff --git a/src/Components/Patient/ManagePatients.tsx b/src/Components/Patient/ManagePatients.tsx index ae227bbbb6..16b4e5dab5 100644 --- a/src/Components/Patient/ManagePatients.tsx +++ b/src/Components/Patient/ManagePatients.tsx @@ -2,6 +2,7 @@ import * as Notification from "../../Utils/Notifications.js"; import { ADMITTED_TO, + CONSENT_TYPE_CHOICES, DISCHARGE_REASONS, GENDER_TYPES, PATIENT_CATEGORIES, @@ -194,6 +195,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__consent_types: + qParams.last_consultation__consent_types || undefined, last_consultation__new_discharge_reason: qParams.last_consultation__new_discharge_reason || undefined, last_consultation_current_bed__location: @@ -395,6 +398,16 @@ export const PatientManager = () => { }, ); + const { data: patientsWithNoConsentsData } = useQuery(routes.patientList, { + query: { + limit: 1, + last_consultation__consent_types: "None", + is_active: "True", + }, + }); + + const patientsWithNoConsents = patientsWithNoConsentsData?.count; + const { data: permittedFacilities } = useQuery( routes.getPermittedFacilities, { @@ -431,6 +444,39 @@ export const PatientManager = () => { }); }; + const HasConsentTypesBadges = () => { + const badge = (key: string, value: any, id: string) => { + return ( + value && ( + { + const lcat = qParams.last_consultation__consent_types + .split(",") + .filter((x: string) => x != id) + .join(","); + updateQuery({ + ...qParams, + last_consultation__consent_types: lcat, + }); + }} + /> + ) + ); + }; + + return qParams.last_consultation__consent_types + .split(",") + .map((id: string) => { + const text = [ + ...CONSENT_TYPE_CHOICES, + { id: "None", text: "None" }, + ].find((obj) => obj.id == id)?.text; + return badge("Has Consent", text, id); + }); + }; + const getDiagnosisFilterValue = (key: DiagnosesFilterKey) => { const ids: string[] = (qParams[key] ?? "").split(","); return ids.map((id) => diagnoses.find((obj) => obj.id == id)?.label ?? id); @@ -645,6 +691,20 @@ export const PatientManager = () => { )} + {patient.has_consents || ( + + + + + + + + )}
@@ -932,7 +992,23 @@ export const PatientManager = () => { -
+ {!qParams.last_consultation__consent_types && patientsWithNoConsents && ( +
+ +

+ {patientsWithNoConsents} patients admitted without consent.  + +

+
+ )} +
{ ), ]} children={ - qParams.last_consultation_admitted_bed_type_list && - LastAdmittedToTypeBadges() + (qParams.last_consultation_admitted_bed_type_list || + qParams.last_consultation__consent_types) && ( + <> + {qParams.last_consultation_admitted_bed_type_list && + LastAdmittedToTypeBadges()} + {qParams.last_consultation__consent_types && + HasConsentTypesBadges()} + + ) } />
diff --git a/src/Components/Patient/PatientConsentRecords.tsx b/src/Components/Patient/PatientConsentRecords.tsx index d850179c6d..b075a568ac 100644 --- a/src/Components/Patient/PatientConsentRecords.tsx +++ b/src/Components/Patient/PatientConsentRecords.tsx @@ -1,4 +1,4 @@ -import { useEffect, useState } from "react"; +import { useState } from "react"; import { CONSENT_PATIENT_CODE_STATUS_CHOICES, CONSENT_TYPE_CHOICES, @@ -34,12 +34,6 @@ export default function PatientConsentRecords(props: { patient_code_status: 4, }); - const refetchAll = () => { - refetch(); - refetchFiles(); - refetchArchivedFiles(); - }; - const fileUpload = useFileUpload({ type: "CONSENT_RECORD", allowedExtensions: ["pdf", "jpg", "jpeg", "png"], @@ -48,10 +42,10 @@ export default function PatientConsentRecords(props: { const fileManager = useFileManager({ type: "CONSENT_RECORD", onArchive: async () => { - refetchAll(); + refetch(); }, onEdit: async () => { - refetchAll(); + refetch(); }, }); @@ -73,36 +67,6 @@ export default function PatientConsentRecords(props: { const consentRecords = consentRecordsData?.results; - const { data: unarchivedFiles, refetch: refetchFiles } = useQuery( - routes.viewUpload, - { - query: { - file_type: "CONSENT_RECORD", - associating_id: consentRecords?.map((cr) => cr.id).join(","), - limit: 1000, - offset: 0, - is_archived: false, - }, - prefetch: (consentRecords?.length || 0) > 0 && showArchived, - }, - ); - - const { data: archivedFiles, refetch: refetchArchivedFiles } = useQuery( - routes.viewUpload, - { - query: { - file_type: "CONSENT_RECORD", - associating_id: consentRecords?.map((cr) => cr.id).join(","), - limit: 1000, - offset: 0, - is_archived: true, - }, - prefetch: (consentRecords?.length || 0) > 0 && !showArchived, - }, - ); - - const files = showArchived ? archivedFiles : unarchivedFiles; - const selectField = (name: string) => { return { name, @@ -135,13 +99,6 @@ export default function PatientConsentRecords(props: { refetch(); }; - useEffect(() => { - if (consentRecords && consentRecords.length > 0) { - refetchFiles(); - refetchArchivedFiles(); - } - }, [consentRecords]); - return ( {consentRecords?.filter( (r) => - files?.results.filter((f) => f.associating_id === r.id).length, + r.files?.filter( + (f) => + f.associating_id === r.id && f.is_archived === showArchived, + ).length, ).length === 0 ? (
No consent records found
) : ( - (!unarchivedFiles || !archivedFiles) && !consentRecords && (
) @@ -301,8 +260,10 @@ export default function PatientConsentRecords(props: { archiveFile={fileManager.archiveFile} editFile={fileManager.editFile} showArchive={showArchived} - files={files?.results.filter( - (f) => f.associating_id === record.id, + files={record.files?.filter( + (f) => + f.associating_id === record.id && + showArchived === f.is_archived, )} /> ))} diff --git a/src/Components/Patient/PatientFilter.tsx b/src/Components/Patient/PatientFilter.tsx index f153f9aa93..b69436171d 100644 --- a/src/Components/Patient/PatientFilter.tsx +++ b/src/Components/Patient/PatientFilter.tsx @@ -3,6 +3,7 @@ import CareIcon from "../../CAREUI/icons/CareIcon"; import FiltersSlideover from "../../CAREUI/interactive/FiltersSlideover"; import { ADMITTED_TO, + CONSENT_TYPE_CHOICES, DISCHARGE_REASONS, FACILITY_TYPES, GENDER_TYPES, @@ -78,6 +79,7 @@ export default function PatientFilter(props: any) { filter.last_consultation_admitted_bed_type_list ? filter.last_consultation_admitted_bed_type_list.split(",") : [], + last_consultation__consent_types: filter.last_consultation__consent_types, last_consultation_current_bed__location: filter.last_consultation_current_bed__location || "", last_consultation__new_discharge_reason: @@ -183,6 +185,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__consent_types, last_consultation__new_discharge_reason, last_consultation_current_bed__location, number_of_doses, @@ -241,6 +244,7 @@ export default function PatientFilter(props: any) { age_max: age_max || "", last_consultation_admitted_bed_type_list: last_consultation_admitted_bed_type_list || [], + last_consultation__consent_types: last_consultation__consent_types, last_consultation__new_discharge_reason: last_consultation__new_discharge_reason || "", number_of_doses: number_of_doses || "", @@ -373,6 +377,26 @@ export default function PatientFilter(props: any) { />
)} + {(props.dischargePage || ["StateAdmin", "StateReadOnlyAdmin"].includes( authUser.user_type, diff --git a/src/Components/Patient/models.tsx b/src/Components/Patient/models.tsx index 9664d0f462..c697b989d0 100644 --- a/src/Components/Patient/models.tsx +++ b/src/Components/Patient/models.tsx @@ -136,6 +136,8 @@ export interface PatientModel { // ABDM related abha_number?: string; abha_number_object?: AbhaObject; + + has_consents?: boolean; } export interface SampleTestModel { From cb91bebf57db4907ca1efb8b72d91c44d8c45e75 Mon Sep 17 00:00:00 2001 From: Shivank Kacker Date: Sun, 9 Jun 2024 05:11:30 +0530 Subject: [PATCH 2/7] fix info card --- src/Components/Patient/PatientInfoCard.tsx | 24 ++++++---------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/Components/Patient/PatientInfoCard.tsx b/src/Components/Patient/PatientInfoCard.tsx index 0b05009d4a..aa780c180d 100644 --- a/src/Components/Patient/PatientInfoCard.tsx +++ b/src/Components/Patient/PatientInfoCard.tsx @@ -150,20 +150,6 @@ export default function PatientInfoCard(props: { }, ); - const { data: consentFiles, loading: consentFilesLoading } = useQuery( - routes.viewUpload, - { - query: { - file_type: "CONSENT_RECORD", - associating_id: consentRecords?.results.map((cr) => cr.id).join(","), - limit: 1, - offset: 0, - is_archived: false, - }, - prefetch: (consentRecords?.results.length || 0) > 0, - }, - ); - return ( <>
)} - {!consentFilesLoading && - !consentRecordsLoading && - !consentFiles?.results.filter((c) => !c.is_archived) - .length && ( + {!consentRecordsLoading && + !consentRecords?.results.filter( + (c) => + !c.archived && + c.files?.filter((f) => !f.is_archived).length, + ).length && (
From b918228cfd780fa0c35a9f4af8c6f9a28c8c8a9b Mon Sep 17 00:00:00 2001 From: Shivank Kacker Date: Tue, 11 Jun 2024 17:37:44 +0530 Subject: [PATCH 3/7] string change --- src/Components/Patient/ManagePatients.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Components/Patient/ManagePatients.tsx b/src/Components/Patient/ManagePatients.tsx index 16b4e5dab5..18e62fa987 100644 --- a/src/Components/Patient/ManagePatients.tsx +++ b/src/Components/Patient/ManagePatients.tsx @@ -996,7 +996,8 @@ export const PatientManager = () => {

- {patientsWithNoConsents} patients admitted without consent.  + {patientsWithNoConsents} patients admitted missing consent + records 

- {!qParams.last_consultation__consent_types && patientsWithNoConsents && ( -
- -

- {patientsWithNoConsents} patients admitted missing consent - records  - -

-
- )} + {!qParams.last_consultation__consent_types && + (patientsWithNoConsents || 0) > 0 && ( +
+ +

+ {patientsWithNoConsents} patients admitted missing consent + records  + +

+
+ )}
Date: Sat, 15 Jun 2024 15:04:21 +0530 Subject: [PATCH 5/7] made alert filter sensitive --- src/Components/Patient/ManagePatients.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/Patient/ManagePatients.tsx b/src/Components/Patient/ManagePatients.tsx index 42d3a071a3..38089183ef 100644 --- a/src/Components/Patient/ManagePatients.tsx +++ b/src/Components/Patient/ManagePatients.tsx @@ -400,7 +400,7 @@ export const PatientManager = () => { const { data: patientsWithNoConsentsData } = useQuery(routes.patientList, { query: { - facility: qParams.facility, + ...qParams, limit: 1, last_consultation__consent_types: "None", is_active: "True", From 543b579f3aec309bec44135a344fd2e2b5f21872 Mon Sep 17 00:00:00 2001 From: Shivank Kacker Date: Mon, 24 Jun 2024 23:15:33 +0530 Subject: [PATCH 6/7] type changes --- src/Components/Facility/models.tsx | 1 + src/Components/Patient/ManagePatients.tsx | 2 +- src/Components/Patient/models.tsx | 2 -- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Components/Facility/models.tsx b/src/Components/Facility/models.tsx index 1b8cd966a5..08d0b7a6de 100644 --- a/src/Components/Facility/models.tsx +++ b/src/Components/Facility/models.tsx @@ -185,6 +185,7 @@ export interface ConsultationModel { is_readmission?: boolean; medico_legal_case?: boolean; investigation?: InvestigationType[]; + has_consents?: boolean; } export interface PatientStatsModel { diff --git a/src/Components/Patient/ManagePatients.tsx b/src/Components/Patient/ManagePatients.tsx index fe1758ea0a..f150bbcc01 100644 --- a/src/Components/Patient/ManagePatients.tsx +++ b/src/Components/Patient/ManagePatients.tsx @@ -704,7 +704,7 @@ export const PatientManager = () => { )} - {patient.has_consents || ( + {patient.last_consultation?.has_consents || ( Date: Mon, 24 Jun 2024 23:19:52 +0530 Subject: [PATCH 7/7] minor fix --- src/Components/Patient/PatientInfoCard.tsx | 30 ++++++---------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/src/Components/Patient/PatientInfoCard.tsx b/src/Components/Patient/PatientInfoCard.tsx index 31bd19413b..23760039a9 100644 --- a/src/Components/Patient/PatientInfoCard.tsx +++ b/src/Components/Patient/PatientInfoCard.tsx @@ -140,15 +140,6 @@ export default function PatientInfoCard(props: { }, prefetch: !!consultation?.treating_physician_object?.username, }); - const { data: consentRecords, loading: consentRecordsLoading } = useQuery( - routes.listConsents, - { - pathParams: { - consultationId: consultation?.id ?? "", - }, - prefetch: !!consultation?.id, - }, - ); return ( <> @@ -364,20 +355,15 @@ export default function PatientInfoCard(props: {
)} - {!consentRecordsLoading && - !consentRecords?.results.filter( - (c) => - !c.archived && - c.files?.filter((f) => !f.is_archived).length, - ).length && ( -
-
- - Consent Records Missing - -
+ {consultation?.has_consents || ( +
+
+ + Consent Records Missing +
- )} +
+ )} {consultation?.suggestion === "DC" && (