Skip to content

Commit

Permalink
added consent requests table for facilities in abdm
Browse files Browse the repository at this point in the history
  • Loading branch information
khavinshankar committed Dec 19, 2023
1 parent b253950 commit 9f171d6
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 2 deletions.
146 changes: 146 additions & 0 deletions src/Components/ABDM/ABDMFacilityRecords.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import { Link } from "raviger";
import routes from "../../Redux/api";
import useQuery from "../../Utils/request/useQuery";
import { formatDateTime } from "../../Utils/utils";
import Loading from "../Common/Loading";
import Page from "../Common/components/Page";

interface IProps {
facilityId: string;
}

const TableHeads = [
"Patient",
"Status",
"Created On",
"Requested By",
"Health Information Range",
"Expires On",
"HI Profiles",
];

export default function ABDMFacilityRecords({ facilityId }: IProps) {
const { data: consentsResult, loading } = useQuery(routes.listConsents, {
query: { facility: facilityId, ordering: "-created_date" },
});

if (loading) {
return <Loading />;
}

return (
<Page title="ABDM Consent Requests">
<div className="px-4 sm:px-6 lg:px-8">
<div className="sm:flex sm:items-center"></div>
<div className="mt-8 flow-root">
<div className="-mx-4 -my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
<div className="inline-block min-w-full py-2 align-middle sm:px-6 lg:px-8">
{/* eslint-disable-next-line tailwindcss/migration-from-tailwind-2 */}
<div className="overflow-hidden shadow ring-1 ring-black ring-opacity-5 sm:rounded-lg">
<table className="min-w-full table-fixed divide-y divide-gray-300">
<thead className="bg-gray-50">
<tr>
{TableHeads.map((head) => (
<th
scope="col"
className="px-3 py-3.5 text-center text-sm font-semibold text-gray-900"
>
{head}
</th>
))}
<th
scope="col"
className="sticky right-0 top-0 py-3.5 pl-3 pr-4 sm:pr-6"
>
<span className="sr-only">View</span>
</th>
</tr>
</thead>
<tbody className="divide-y divide-gray-200 bg-white">
{consentsResult?.results.map((consent) => (
<tr key={consent.id}>
<td className="px-3 py-4 text-center text-sm">
{consent.patient_abha_object?.name}
<p className="text-gray-600">
({consent.patient_abha})
</p>
</td>

<td className="px-3 py-4 text-center text-sm capitalize">
{consent.status}
</td>

<td className="px-3 py-4 text-center text-sm">
{formatDateTime(consent.created_date)}
</td>

<td className="px-3 py-4 text-center text-sm">
{`${consent.requester?.first_name} ${consent.requester?.last_name}`.trim()}
<p className="text-gray-600">
({consent.requester.username})
</p>
</td>

<td className="px-3 py-4 text-center text-sm">
{formatDateTime(
consent.consent_artefacts?.[0]?.from_time ??
consent.from_time
)}{" "}
<br />
{formatDateTime(
consent.consent_artefacts?.[0]?.to_time ??
consent.to_time
)}
</td>

<td className="px-3 py-4 text-center text-sm">
{formatDateTime(
consent.consent_artefacts?.[0]?.expiry ??
consent.expiry
)}
</td>

<td className="px-3 py-4 text-center text-sm">
<div className="flex flex-wrap items-center justify-center">
{(
consent.consent_artefacts?.[0]?.hi_types ??
consent.hi_types
)?.map((hiType) => (
<span className="mb-2 mr-2 rounded-full bg-gray-100 px-2 py-1 text-xs font-medium text-gray-600">
{hiType}
</span>
))}
</div>
</td>

<td className="sticky right-0 whitespace-nowrap bg-white py-4 pl-3 pr-4 text-right text-sm font-medium sm:pr-6">
<div className="flex flex-col items-center justify-center gap-2">
{consent.consent_artefacts?.map((artefact, i) =>
artefact.status === "GRANTED" ? (
<Link
key={artefact.id}
href={`/abdm/health-information/${artefact.id}`}
className="cursor-pointer text-primary-600 hover:text-primary-900"
>
View Artefact {i + 1}
</Link>
) : (
<p className="cursor-not-allowed text-gray-600 opacity-70 ">
Artefact {i + 1}
</p>
)
)}
</div>
</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</Page>
);
}
5 changes: 3 additions & 2 deletions src/Components/ABDM/FetchRecordsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default function FetchRecordsModal({ patient, show, onClose }: IProps) {
const [isMakingConsentRequest, setIsMakingConsentRequest] = useState(false);
const [hiTypes, setHiTypes] = useState<string[]>([]);
const [expiryDate, setExpiryDate] = useState<Date>(
dayjs().add(30, "days").toDate()
dayjs().add(5, "minutes").toDate()
);
const [errors, setErrors] = useState<any>({});

Expand Down Expand Up @@ -196,7 +196,8 @@ export default function FetchRecordsModal({ patient, show, onClose }: IProps) {
});

navigate(
`/facility/${patient.facility}/patient/${patient.id}/consultation/${patient.last_consultation?.id}/abdm`
`/facility/${patient.facility}/abdm` ??
`/facility/${patient.facility}/patient/${patient.id}/consultation/${patient.last_consultation?.id}/abdm`
);
} else {
Notification.Error({
Expand Down
1 change: 1 addition & 0 deletions src/Components/ABDM/HealthInformation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface IProps {
export default function HealthInformation({ artefactId }: IProps) {
const { data, loading, error } = useQuery(routes.getHealthInformation, {
pathParams: { artefactId },
silent: true,
});

if (loading) {
Expand Down
21 changes: 21 additions & 0 deletions src/Components/ABDM/types/abha.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export type AbhaNumberModel = {
id: number;
external_id: string;
created_date: string;
modified_date: string;
abha_number: string;
health_id: string;
name: string;
first_name: string | null;
middle_name: string | null;
last_name: string | null;
gender: "F" | "M" | "O";
date_of_birth: string | null;
address: string | null;
district: string | null;
state: string | null;
pincode: string | null;
email: string | null;
profile_photo: string | null;
new: boolean;
};
2 changes: 2 additions & 0 deletions src/Components/ABDM/types/consent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { UserBaseModel } from "../../Users/models";
import { AbhaNumberModel } from "./abha";

export type ConsentPurpose =
| "CAREMGT"
Expand Down Expand Up @@ -68,5 +69,6 @@ export type ConsentArtefactModel = {

export type ConsentRequestModel = {
requester: UserBaseModel;
patient_abha_object: AbhaNumberModel;
consent_artefacts: ConsentArtefactModel[];
} & ConsentModel;
7 changes: 7 additions & 0 deletions src/Components/Facility/FacilityHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,13 @@ export const FacilityHome = (props: any) => {
>
View Users
</DropdownItem>
<DropdownItem
id="view-abdm-records"
onClick={() => navigate(`/facility/${facilityId}/abdm`)}
icon={<CareIcon className="care-l-file-network text-lg" />}
>
View ABDM Records
</DropdownItem>
<DropdownItem
id="delete-facility"
variant="danger"
Expand Down
7 changes: 7 additions & 0 deletions src/Redux/api.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IConfig } from "../Common/hooks/useConfig";
import { ConsentRequestModel } from "../Components/ABDM/types/consent";
import { HealthInformationModel } from "../Components/ABDM/types/health-information";
import { AssetData } from "../Components/Assets/AssetTypes";
import { LocationModel } from "../Components/Facility/models";
Expand Down Expand Up @@ -957,6 +958,12 @@ const routes = {
listConsents: {
path: "/api/v1/abdm/consent/",
method: "GET",
TRes: Type<{
results: ConsentRequestModel[];
count: number;
next: string | null;
previous: string | null;
}>(),
},

createConsent: {
Expand Down
4 changes: 4 additions & 0 deletions src/Routers/AppRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import SessionExpired from "../Components/ErrorPages/SessionExpired";
import ManagePrescriptions from "../Components/Medicine/ManagePrescriptions";
import CentralNursingStation from "../Components/Facility/CentralNursingStation";
import HealthInformation from "../Components/ABDM/HealthInformation";
import ABDMFacilityRecords from "../Components/ABDM/ABDMFacilityRecords";

export default function AppRouter() {
const { main_logo, enable_hcx } = useConfig();
Expand Down Expand Up @@ -406,6 +407,9 @@ export default function AppRouter() {
"/abdm/health-information/:id": ({ id }: { id: string }) => (
<HealthInformation artefactId={id} />
),
"/facility/:facilityId/abdm": ({ facilityId }: any) => (
<ABDMFacilityRecords facilityId={facilityId} />
),
"/session-expired": () => <SessionExpired />,
"/not-found": () => <Error404 />,
};
Expand Down

0 comments on commit 9f171d6

Please sign in to comment.