Skip to content

Commit

Permalink
Merge pull request #128 from sainingo/providers
Browse files Browse the repository at this point in the history
(feat) Add all providers
  • Loading branch information
Rugute authored Jul 25, 2024
2 parents 71815fc + bd70454 commit 3e9ac05
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 95 deletions.
33 changes: 33 additions & 0 deletions packages/esm-providers-app/src/api/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import useSWR from 'swr';
import { Buffer } from 'buffer';
import { openmrsFetch, restBaseUrl, useConfig } from '@openmrs/esm-framework';

export const BASE_URL = '/ws/rest/v1/provider?v=full';
export const custom =
'/ws/rest/v1/provider?&v=custom:(uuid,identifier,display,person:(uuid,display),attributes:(uuid,display),retired)';

const fetcher = async (url) => {
try {
const response = await openmrsFetch(url, {});
if (!response.ok) {
throw new Error(`Failed to fetch data: ${response.statusText}`);
}

return response.json();
} catch (error) {
throw new Error(`An error occurred while fetching data: ${error.message}`);
}
};

export const getAllProviders = () => {
const { data, isLoading, error, isValidating } = useSWR(`${custom}`, fetcher);

const response = data ? (data as any)?.results : [];

return {
response,
isLoading,
error,
isValidating,
};
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo, useState } from 'react';
import React, { useEffect, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import {
Table,
Expand All @@ -17,108 +17,37 @@ import {
OverflowMenuItem,
} from '@carbon/react';
import { usePagination } from '@openmrs/esm-framework';
import { getAllProviders } from '../api/api';
import { use } from 'i18next';

export const Admissionqueue: React.FC = () => {
const { t } = useTranslation();
const [currentPageSize, setCurrentPageSize] = useState<number>(10);
const [currentPageSize, setCurrentPageSize] = useState<number>(5);
const { response, isLoading, error, isValidating } = getAllProviders();

// Dummy data for AdmissionWorkListEntries
const AdmissionWorkListEntries = [
{
id: 1,
name: 'John Doe',
date: '2024-03-20',
license: 'TEST_123',
created: 'Admin',
'date-created': '2024-03-19',
},
{
id: 2,
name: 'Jane Smith',
date: '2024-03-21',
license: 'TEST_124',
created: 'Doctor',
'date-created': '2024-03-20',
},
// {
// id: 3,
// name: 'Alice Johnson',
// date: '2024-03-22',
// cause: 'Accident',
// created: 'Nurse',
// 'date-created': '2024-03-21',
// },
// {
// id: 4,
// name: 'Bob Brown',
// date: '2024-03-23',
// cause: 'Infection',
// created: 'Admin',
// 'date-created': '2024-03-22',
// },
// {
// id: 5,
// name: 'Eva Garcia',
// date: '2024-03-24',
// cause: 'Allergic Reaction',
// created: 'Doctor',
// 'date-created': '2024-03-23',
// },
// {
// id: 6,
// name: 'Michael Lee',
// date: '2024-03-25',
// cause: 'Food Poisoning',
// created: 'Nurse',
// 'date-created': '2024-03-24',
// },
// {
// id: 7,
// name: 'Sophia Martinez',
// date: '2024-03-26',
// cause: 'Burn',
// created: 'Admin',
// 'date-created': '2024-03-25',
// },
// {
// id: 8,
// name: 'William Wilson',
// date: '2024-03-27',
// cause: 'Fracture',
// created: 'Doctor',
// 'date-created': '2024-03-26',
// },
// {
// id: 9,
// name: 'Olivia Taylor',
// date: '2024-03-28',
// cause: 'Pneumonia',
// created: 'Nurse',
// 'date-created': '2024-03-27',
// },
// {
// id: 10,
// name: 'Daniel Anderson',
// date: '2024-03-29',
// cause: 'Appendicitis',
// created: 'Admin',
// 'date-created': '2024-03-28',
// },
// Add more entries as needed
];
useEffect(() => {}, [response, isLoading, error, isValidating]);

const isLoading = false;
const filteredResult = response.map((provider) => {
// Extract custom attributes
const licenseNumberAttr = provider.attributes.find((attr) => attr.display.startsWith('Licence Number'));
const licenseExpiryDateAttr = provider.attributes.find((attr) => attr.display.startsWith('Licence Expiry Date'));

const searchResults = AdmissionWorkListEntries.filter(() => {
return true; // No filtering applied for now
return {
id: provider.uuid,
identifier: provider.identifier,
name: provider.person.display,
licenseNumber: licenseNumberAttr ? licenseNumberAttr.display.split(': ')[1] : null,
licenseExpiryDate: licenseExpiryDateAttr ? licenseExpiryDateAttr.display.split(': ')[1] : null,
};
});

const { goTo, results: paginatedResults, currentPage } = usePagination(searchResults, currentPageSize);
const { goTo, results: paginatedResults, currentPage } = usePagination(filteredResult, currentPageSize);

// const pageSizes = [5, 10, 15, 20, 25];
const pageSizes = [10, 20, 30, 40, 50];

const rows = useMemo(() => {
return paginatedResults.map((entry) => ({
return paginatedResults.map((entry: any) => ({
...entry,
action: (
<OverflowMenu flipped={document?.dir === 'rtl'} aria-label="overflow-menu">
Expand All @@ -133,8 +62,8 @@ export const Admissionqueue: React.FC = () => {
const tableColumns = [
{ id: 0, header: t('id', 'IDENTIFIER'), key: 'id' },
{ id: 1, header: t('name', 'NAME'), key: 'name' },
{ id: 2, header: t('license', 'LICENSE NUMBER'), key: 'license' },
{ id: 3, header: t('date', 'LICENSE EXPIRY DATE'), key: 'date' },
{ id: 2, header: t('licenseNumber', 'LICENSE NUMBER'), key: 'licenseNumber' },
{ id: 3, header: t('licenseExpiryDate', 'LICENSE EXPIRY DATE'), key: 'licenseExpiryDate' },
{ id: 4, header: t('action', 'ACTION'), key: 'action' },
];

Expand Down Expand Up @@ -186,7 +115,7 @@ export const Admissionqueue: React.FC = () => {
page={currentPage}
pageSize={currentPageSize}
pageSizes={pageSizes}
totalItems={AdmissionWorkListEntries.length}
totalItems={response.length}
onChange={({ pageSize, page }) => {
if (pageSize !== currentPageSize) {
setCurrentPageSize(pageSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export const ProvidersTabs: React.FC = () => {
<TabPanel>
<Admissionqueue />
</TabPanel>
<TabPanel>
<Admissionqueue />
</TabPanel>
</TabPanels>
</Tabs>
</main>
Expand Down
3 changes: 2 additions & 1 deletion packages/esm-providers-app/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
"id": "IDENTIFIER",
"inactive": "InActive Providers",
"inactivet": "Total InActive Providers",
"license": "LICENCE NUMBER",
"licenseDue": "License Due",
"licenseDuet": "Total with License Due for Renewal",
"licenseExpiryDate": "LICENSE EXPIRY DATE",
"licenseNumber": "LICENSE NUMBER",
"morgue": "Provider Management",
"name": "NAME",
"paid": "paid bill",
Expand Down

0 comments on commit 3e9ac05

Please sign in to comment.