diff --git a/src/Common/hooks/useFilters.tsx b/src/Common/hooks/useFilters.tsx
index a59b8e1e00..c0919be9ac 100644
--- a/src/Common/hooks/useFilters.tsx
+++ b/src/Common/hooks/useFilters.tsx
@@ -184,13 +184,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..f978467616 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;
@@ -180,6 +185,7 @@ export interface ConsultationModel {
is_readmission?: boolean;
medico_legal_case?: boolean;
investigation?: InvestigationType[];
+ has_consents?: (typeof CONSENT_TYPE_CHOICES)[number]["id"][];
}
export interface PatientStatsModel {
diff --git a/src/Components/Patient/ManagePatients.tsx b/src/Components/Patient/ManagePatients.tsx
index dbd263463d..b6fc98935e 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,
@@ -195,6 +196,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:
@@ -396,6 +399,17 @@ export const PatientManager = () => {
},
);
+ const { data: patientsWithNoConsentsData } = useQuery(routes.patientList, {
+ query: {
+ ...qParams,
+ limit: 1,
+ last_consultation__consent_types: "None",
+ is_active: "True",
+ },
+ });
+
+ const patientsWithNoConsents = patientsWithNoConsentsData?.count;
+
const { data: permittedFacilities } = useQuery(
routes.getPermittedFacilities,
{
@@ -432,6 +446,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: "No Consents" },
+ ].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);
@@ -660,6 +707,20 @@ export const PatientManager = () => {
)}
+ {!!patient.last_consultation?.has_consents.length || (
+
+
+
+
+
+
+
+ )}
@@ -949,7 +1010,25 @@ export const PatientManager = () => {
-
+ {!qParams.last_consultation__consent_types &&
+ (patientsWithNoConsents || 0) > 0 && (
+
+
+
+ {patientsWithNoConsents} patients admitted missing consent
+ records
+
+
+
+ )}
+
{
),
]}
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 7faf670219..a8b94f2d04 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) {
/>
)}
+
+ Has consent records for
+ o.id}
+ optionLabel={(o) => o.text}
+ onChange={(o) =>
+ setFilterState({
+ ...filterState,
+ last_consultation__consent_types: o,
+ })
+ }
+ />
+
{(props.dischargePage ||
["StateAdmin", "StateReadOnlyAdmin"].includes(
authUser.user_type,
diff --git a/src/Components/Patient/PatientInfoCard.tsx b/src/Components/Patient/PatientInfoCard.tsx
index 66545447e7..f58af22842 100644
--- a/src/Components/Patient/PatientInfoCard.tsx
+++ b/src/Components/Patient/PatientInfoCard.tsx
@@ -133,29 +133,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,
- },
- );
-
- 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 (
<>
@@ -371,18 +348,15 @@ export default function PatientInfoCard(props: {
)}
- {!consentFilesLoading &&
- !consentRecordsLoading &&
- !consentFiles?.results.filter((c) => !c.is_archived)
- .length && (
-
-
-
- Consent Records Missing
-
-
+ {!!consultation?.has_consents?.length || (
+
+
+
+ Consent Records Missing
+
- )}
+
+ )}
{consultation?.suggestion === "DC" && (