Skip to content

Commit

Permalink
refactor: adding filter types into perimeters/read-patient/
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehdi-BOUYAHIA committed Apr 4, 2023
1 parent db8e2f4 commit 4eca382
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/services/aphp/callApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,16 +609,20 @@ export const fetchMedicationAdministration = async (args: fetchMedicationAdminis
type fetchScopeProps = {
perimetersIds?: string[]
cohortIds?: string[]
types?: string[]
}
export const fetchScope: (args: fetchScopeProps) => Promise<AxiosResponse<IScope | unknown>> = async (
args: fetchScopeProps
) => {
const { perimetersIds, cohortIds } = args
const { perimetersIds, cohortIds, types } = args

let options: string[] = []
if (perimetersIds && perimetersIds.length > 0) options = [...options, `local_id=${perimetersIds.join(',')}`] // eslint-disable-line
if (cohortIds && cohortIds.length > 0) options = [...options, `cohort_id=${cohortIds.join(',')}`] // eslint-disable-line
if (types && types.length > 0) options = [...options, `type_source_value=${types.join(',')}`] // eslint-disable-line

const response: AxiosResponse<IScope | unknown> = await apiBackend.get(`accesses/perimeters/read-patient/?${options}`)
const response: AxiosResponse<IScope | unknown> = await apiBackend.get(
`accesses/perimeters/read-patient/?${options.reduce(optionsReducer)}`
)
return response
}
18 changes: 14 additions & 4 deletions src/services/aphp/servicePerimeters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ export interface IServicePerimeters {
defaultPerimetersIds?: string[],
cohortIds?: string[],
noPerimetersIdsFetch?: boolean,
signal?: AbortSignal
signal?: AbortSignal,
types?: string[]
) => Promise<ScopePage[]>

/**
Expand Down Expand Up @@ -228,7 +229,8 @@ const servicesPerimeters: IServicePerimeters = {
defaultPerimetersIds?: string[],
cohortIds?: string[],
noPerimetersIdsFetch?: boolean,
signal?: AbortSignal
signal?: AbortSignal,
types?: string[]
) => {
try {
let perimetersIds: string[] | undefined = []
Expand All @@ -252,7 +254,11 @@ const servicesPerimeters: IServicePerimeters = {
perimetersIds = defaultPerimetersIds
}

const perimetersListReponse: any = await fetchScope({ perimetersIds: perimetersIds, cohortIds: cohortIds })
const perimetersListReponse: any = await fetchScope({
perimetersIds: perimetersIds,
cohortIds: cohortIds,
types: types
})
if (!perimetersListReponse || !perimetersListReponse.data || !perimetersListReponse.data.results) {
console.error(
'Error (getPerimeters) while fetching perimeter (from back) ! perimeters = {}, cohortIds = {}',
Expand Down Expand Up @@ -296,11 +302,15 @@ const servicesPerimeters: IServicePerimeters = {

getScopeSubItems: async (subScopesIds: string | null | undefined, getSubItem?: boolean, signal?: AbortSignal) => {
if (!subScopesIds) return []

const types = ['AP-HP', 'GHU', 'Hôpital', 'Groupe hospitalier (GH)', 'Pôle/DMU', 'Unité Fonctionnelle (UF)']

const subScopes: ScopePage[] = await servicesPerimeters.getPerimeters(
subScopesIds.trim().split(','),
undefined,
undefined,
signal
signal,
types
)
const scopeRowList: ScopeTreeRow[] = await servicesPerimeters.buildScopeTreeRow(subScopes, getSubItem, signal)
return scopeRowList
Expand Down

0 comments on commit 4eca382

Please sign in to comment.