Skip to content

Commit

Permalink
refactor: change url fhir to django for getting users info and refact…
Browse files Browse the repository at this point in the history
…o some django call Ref gestion-de-projet#1979 (#736)
  • Loading branch information
ManelleG authored Mar 28, 2023
2 parents 2c40ddd + e1417a1 commit d756c63
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 69 deletions.
4 changes: 0 additions & 4 deletions src/services/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -242,8 +240,6 @@ export interface IServicePractitioner {
firstName: string
lastName: string
} | null>

fetchPractitionerRole: (practionerId: string) => Promise<any>
}
```

Expand Down
30 changes: 1 addition & 29 deletions src/services/aphp/callApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import {
IMedicationRequest,
IObservation,
IPatient,
IPractitioner,
IPractitionerRole,
IProcedure,
IOrganization
} from '@ahryman40k/ts-fhir-types/lib/R4'
Expand Down Expand Up @@ -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
Expand All @@ -345,33 +344,6 @@ export const fetchBinary = async (args: fetchBinaryProps) => {
return documentResp.data ?? []
}

export const fetchPractitioner = async () => {
return await apiFhir.get<FHIR_API_Response<IPractitioner>>(`/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<FHIR_API_Response<IPractitionerRole>>(`/PractitionerRole?${options.reduce(optionsReducer)}`)
}

/**
* Procedure Resource
*
Expand Down
48 changes: 14 additions & 34 deletions src/services/aphp/servicePractitioner.ts
Original file line number Diff line number Diff line change
@@ -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 {
/**
Expand Down Expand Up @@ -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
Expand All @@ -55,56 +52,39 @@ 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
}
},

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<AxiosResponse>(`/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 {
Expand Down
3 changes: 1 addition & 2 deletions src/views/Login/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -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') {
Expand Down

0 comments on commit d756c63

Please sign in to comment.