From 70f8ab748e5d6a512c64d37f3dec30120e45fdc7 Mon Sep 17 00:00:00 2001 From: Peter Muriuki Date: Fri, 8 Sep 2023 11:51:35 +0300 Subject: [PATCH 1/3] Filter practitioners available for assigment to active --- .../src/components/AddEditOrganization/index.tsx | 4 ++-- .../components/AddEditOrganization/tests/index.test.tsx | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/fhir-team-management/src/components/AddEditOrganization/index.tsx b/packages/fhir-team-management/src/components/AddEditOrganization/index.tsx index 914124246..107aa9257 100644 --- a/packages/fhir-team-management/src/components/AddEditOrganization/index.tsx +++ b/packages/fhir-team-management/src/components/AddEditOrganization/index.tsx @@ -52,7 +52,7 @@ export const AddEditOrganization = (props: AddEditOrganizationProps) => { const practitioners = useQuery( [practitionerResourceType], - () => loadAllResources(fhirBaseUrl, practitionerResourceType), + () => loadAllResources(fhirBaseUrl, practitionerResourceType, { active: true }), { select: (res) => getResourcesFromBundle(res) as IPractitionerRole[], onError: () => sendErrorNotification(t('There was a problem fetching practitioners')), @@ -62,7 +62,7 @@ export const AddEditOrganization = (props: AddEditOrganizationProps) => { // practitioners already assigned to this organization const allPractitionerRoles = useQuery( [practitionerResourceType, organizationResourceType, orgId], - () => loadAllResources(fhirBaseUrl, practitionerRoleResourceType), + () => loadAllResources(fhirBaseUrl, practitionerRoleResourceType, { active: true }), { onError: () => sendErrorNotification(t('There was a problem fetching assigned practitioners')), diff --git a/packages/fhir-team-management/src/components/AddEditOrganization/tests/index.test.tsx b/packages/fhir-team-management/src/components/AddEditOrganization/tests/index.test.tsx index ee04d6346..c74859872 100644 --- a/packages/fhir-team-management/src/components/AddEditOrganization/tests/index.test.tsx +++ b/packages/fhir-team-management/src/components/AddEditOrganization/tests/index.test.tsx @@ -101,20 +101,20 @@ test('renders correctly for edit locations', async () => { nock(props.fhirBaseURL) .get(`/${practitionerResourceType}/_search`) - .query({ _summary: 'count' }) + .query({ _summary: 'count', active: true }) .reply(200, { total: 1000 }) .get(`/${practitionerResourceType}/_search`) - .query({ _count: 1000 }) + .query({ _count: 1000, active: true }) .reply(200, allPractitioners); nock(props.fhirBaseURL).get(`/${organizationResourceType}/${org105.id}`).reply(200, org105); nock(props.fhirBaseURL) .get(`/${practitionerRoleResourceType}/_search`) - .query({ _summary: 'count' }) + .query({ _summary: 'count', active: true }) .reply(200, { total: 1000 }) .get(`/${practitionerRoleResourceType}/_search`) - .query({ _count: 1000 }) + .query({ _count: 1000, active: true }) .reply(200, allPractitioners); render( From a4ff85517f87c6a915fadcd48d6448812e6956c1 Mon Sep 17 00:00:00 2001 From: Peter Muriuki Date: Fri, 8 Sep 2023 14:11:45 +0300 Subject: [PATCH 2/3] Wait for up-to date request data before loading view --- .../src/components/AddEditOrganization/index.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/fhir-team-management/src/components/AddEditOrganization/index.tsx b/packages/fhir-team-management/src/components/AddEditOrganization/index.tsx index 107aa9257..ffa5c62ef 100644 --- a/packages/fhir-team-management/src/components/AddEditOrganization/index.tsx +++ b/packages/fhir-team-management/src/components/AddEditOrganization/index.tsx @@ -56,6 +56,7 @@ export const AddEditOrganization = (props: AddEditOrganizationProps) => { { select: (res) => getResourcesFromBundle(res) as IPractitionerRole[], onError: () => sendErrorNotification(t('There was a problem fetching practitioners')), + staleTime: 0, } ); @@ -70,13 +71,17 @@ export const AddEditOrganization = (props: AddEditOrganizationProps) => { return getResourcesFromBundle(res) as IPractitionerRole[]; }, enabled: !!orgId, + staleTime: 0, } ); if ( - (!organization.isIdle && organization.isLoading) || - (!practitioners.isIdle && practitioners.isLoading) || - (!allPractitionerRoles.isIdle && allPractitionerRoles.isLoading) + organization.isLoading || + organization.isFetching || + practitioners.isLoading || + practitioners.isFetching || + allPractitionerRoles.isLoading || + allPractitionerRoles.isFetching ) { return ; } From 19a262be3668dcb43affb248f70c33f2940abf9b Mon Sep 17 00:00:00 2001 From: Peter Muriuki Date: Fri, 8 Sep 2023 18:37:53 +0300 Subject: [PATCH 3/3] Remove stale time to prevent alot of reloads --- .../src/components/AddEditOrganization/index.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/fhir-team-management/src/components/AddEditOrganization/index.tsx b/packages/fhir-team-management/src/components/AddEditOrganization/index.tsx index ffa5c62ef..4431f354b 100644 --- a/packages/fhir-team-management/src/components/AddEditOrganization/index.tsx +++ b/packages/fhir-team-management/src/components/AddEditOrganization/index.tsx @@ -56,7 +56,6 @@ export const AddEditOrganization = (props: AddEditOrganizationProps) => { { select: (res) => getResourcesFromBundle(res) as IPractitionerRole[], onError: () => sendErrorNotification(t('There was a problem fetching practitioners')), - staleTime: 0, } ); @@ -71,7 +70,6 @@ export const AddEditOrganization = (props: AddEditOrganizationProps) => { return getResourcesFromBundle(res) as IPractitionerRole[]; }, enabled: !!orgId, - staleTime: 0, } );