-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #128 from sainingo/providers
(feat) Add all providers
- Loading branch information
Showing
4 changed files
with
61 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters