From 555b61f9ac0da5b2b457b78a5963f4ff1865b358 Mon Sep 17 00:00:00 2001 From: Salah-BOUYAHIA Date: Tue, 28 Mar 2023 16:39:41 +0200 Subject: [PATCH 1/2] refactor: refactor some backEnd call into servicePractitionner and change url for getting users info Ref gestion-de-projet#1979 --- src/services/aphp/servicePractitioner.ts | 48 +++++++----------------- src/views/Login/Login.jsx | 3 +- 2 files changed, 15 insertions(+), 36 deletions(-) diff --git a/src/services/aphp/servicePractitioner.ts b/src/services/aphp/servicePractitioner.ts index 9bb31a9b9..4162222cd 100644 --- a/src/services/aphp/servicePractitioner.ts +++ b/src/services/aphp/servicePractitioner.ts @@ -1,8 +1,5 @@ -import axios from 'axios' - -import { BACK_API_URL } from '../../constants' - -import { fetchPractitioner } from './callApi' +import { AxiosResponse } from 'axios' +import apiBackend from 'services/apiBackend' export interface IServicePractitioner { /** @@ -40,7 +37,7 @@ export interface IServicePractitioner { * - firstName: Prénom du practitioner * - lastName: Nom du practitioner */ - fetchPractitioner: () => Promise<{ + fetchPractitioner: (username: string) => Promise<{ id: number displayName: string firstName: string @@ -55,11 +52,7 @@ const servicePractitioner: IServicePractitioner = { formData.append('username', username.toString()) formData.append('password', password) - return await axios({ - method: 'POST', - url: `${BACK_API_URL}/accounts/login/`, - data: formData - }) + return await apiBackend.post(`/accounts/login/`, formData) } catch (error) { console.error("erreur lors de l'exécution de la fonction authenticate", error) return error @@ -67,44 +60,31 @@ const servicePractitioner: IServicePractitioner = { }, logout: async () => { - await axios({ - method: 'POST', - url: `${BACK_API_URL}/accounts/logout/` - }) + await apiBackend.post(`/accounts/logout/`) }, maintenance: async () => { try { - return await axios({ - method: 'GET', - url: `${BACK_API_URL}/maintenances/next/` - }) + return await apiBackend.get(`/maintenance/`) } catch (error) { console.error("erreur lors de l'éxécution de la fonction maintenance", error) return error } }, - fetchPractitioner: async () => { + fetchPractitioner: async (username) => { try { - const practitioner = await fetchPractitioner() + const practitioner: any = await apiBackend.get(`/users/${username}/`) - if ( - !practitioner || - (practitioner && !practitioner.data) || - // @ts-ignore - (practitioner && practitioner.data && !practitioner.data.entry) - ) { + if (!practitioner || (practitioner && !practitioner.data)) { return null } - // @ts-ignore - const { resource } = practitioner.data.entry[0] - const id = resource.id - const userName = resource.identifier[0].value - const firstName = resource.name[0].given.join(' ') - const lastName = resource.name[0].family - const displayName = `${lastName} ${firstName}` + const id = practitioner.data.provider_id + const userName = practitioner.data.provider_username + const firstName = practitioner.data.firstname + const lastName = practitioner.data.lastname + const displayName = `${firstName} ${lastName}` const response = practitioner return { diff --git a/src/views/Login/Login.jsx b/src/views/Login/Login.jsx index 1631bdcd7..60fa6f788 100644 --- a/src/views/Login/Login.jsx +++ b/src/views/Login/Login.jsx @@ -32,7 +32,6 @@ import { ACCES_TOKEN, REFRESH_TOKEN } from '../../constants' import services from 'services/aphp' import useStyles from './styles' -import { ScopePage } from 'types' const ErrorSnackBarAlert = ({ open, setError, errorMessage }) => { const _setError = () => { @@ -107,7 +106,7 @@ const Login = () => { const getPractitionerData = async (practitioner, lastConnection, maintenance) => { if (practitioner) { - const practitionerPerimeters: ScopePage[] | { errorType: string } = await services.perimeters.getPerimeters() + const practitionerPerimeters = await services.perimeters.getPerimeters() if (practitionerPerimeters && practitionerPerimeters.errorType) { if (practitionerPerimeters.errorType === 'fhir') { From e1417a18ab8c35af2903862ae528c39522740497 Mon Sep 17 00:00:00 2001 From: Salah-BOUYAHIA Date: Tue, 28 Mar 2023 16:43:59 +0200 Subject: [PATCH 2/2] refactor: remove unused apiFhir/practitionner call Ref gestion-de-projet#1979 --- src/services/README.md | 4 ---- src/services/aphp/callApi.ts | 30 +----------------------------- 2 files changed, 1 insertion(+), 33 deletions(-) diff --git a/src/services/README.md b/src/services/README.md index feed69609..1eb3b7b0c 100644 --- a/src/services/README.md +++ b/src/services/README.md @@ -108,8 +108,6 @@ Dans un souci de clarté de code, nous avons créé ce fichier `callApi.ts` qui - fetchEncounter - fetchComposition - fetchCompositionContent -- fetchPractitioner -- fetchPractitionerRole - fetchProcedure - fetchClaim - fetchCondition @@ -242,8 +240,6 @@ export interface IServicePractitioner { firstName: string lastName: string } | null> - - fetchPractitionerRole: (practionerId: string) => Promise } ``` diff --git a/src/services/aphp/callApi.ts b/src/services/aphp/callApi.ts index 31780d60a..6ae8b7e41 100644 --- a/src/services/aphp/callApi.ts +++ b/src/services/aphp/callApi.ts @@ -12,8 +12,6 @@ import { IMedicationRequest, IObservation, IPatient, - IPractitioner, - IPractitionerRole, IProcedure, IOrganization } from '@ahryman40k/ts-fhir-types/lib/R4' @@ -328,6 +326,7 @@ export const fetchCompositionContent = async (compositionId: string) => { * Binary Resource * */ + type fetchBinaryProps = { _id?: string; _list?: string[] } export const fetchBinary = async (args: fetchBinaryProps) => { const { _id } = args @@ -345,33 +344,6 @@ export const fetchBinary = async (args: fetchBinaryProps) => { return documentResp.data ?? [] } -export const fetchPractitioner = async () => { - return await apiFhir.get>(`/Practitioner`) -} - -/** - * PractitionerRole Resource - * - */ - -type fetchPractitionerRoleProps = { - practitioner?: string - _elements?: ('extension' | 'organization')[] -} -export const fetchPractitionerRole = async (args: fetchPractitionerRoleProps) => { - const { practitioner } = args - let { _elements } = args - - _elements = _elements ? _elements.filter(uniq) : [] - - let options: string[] = [] - if (practitioner) options = [...options, `practitioner=${practitioner}`] // eslint-disable-line - - if (_elements && _elements.length > 0) options = [...options, `_elements=${_elements.reduce(reducer)}`] // eslint-disable-line - - return await apiFhir.get>(`/PractitionerRole?${options.reduce(optionsReducer)}`) -} - /** * Procedure Resource *