Skip to content

Commit

Permalink
fix: refacto of fhir search params- Ref gestion-de-projet#2522 (#984)
Browse files Browse the repository at this point in the history
* fix: refacto of fhir search params- Ref gestion-de-projet#2522

* refactor: updated fhir search - Ref gestion-de-projet#2522

* fix: remove regex for _text research into valueSetReference - Ref gestion-de-projet#2522

---------

Co-authored-by: manelleg <manelle.gueriouz@aphp.fr>
  • Loading branch information
Mehdi-BOUYAHIA and ManelleG authored Apr 16, 2024
1 parent 2d3bbdc commit 9094ed3
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 40 deletions.
21 changes: 5 additions & 16 deletions src/services/aphp/callApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ type fetchPatientProps = {
minBirthdate?: number
maxBirthdate?: number
searchBy?: string
_text?: string | string[]
_text?: string
deceased?: boolean
pivotFacet?: ('age-month_gender' | 'deceased_gender')[]
_elements?: ('id' | 'gender' | 'name' | 'birthDate' | 'deceased' | 'identifier' | 'extension')[]
Expand Down Expand Up @@ -117,14 +117,7 @@ export const fetchPatient = async (args: fetchPatientProps): FHIR_Bundle_Promise
if (offset) options = [...options, `_offset=${offset}`]
if (_sort) options = [...options, `_sort=${_sortDirection}${_sort}`]
if (gender) options = [...options, `gender=${gender}`]
if (_text && _text.length > 0) {
if (Array.isArray(_text)) {
const searchInput = _text.map((text) => `${searchBy}=${encodeURIComponent(`"${text}"`)}`).join('&')
options = [...options, searchInput]
} else {
options = [...options, `${searchBy}=${_text}`]
}
}
if (_text) options = [...options, `${searchBy}=${_text}`]
if (deceased !== undefined) options = [...options, `deceased=${deceased}`]
if (minBirthdate) options = [...options, `${deidentified ? 'age-month' : 'age-day'}=ge${minBirthdate}`]
if (maxBirthdate) options = [...options, `${deidentified ? 'age-month' : 'age-day'}=le${maxBirthdate}`]
Expand Down Expand Up @@ -955,13 +948,9 @@ const getCodeList = async (
// if search is * then we fetch the roots of the valueSet
if (search !== '*' && search !== undefined) {
// if noStar is true then we search for the code, else we search for the display
searchParam = noStar
? `&only-roots=false&code=${encodeURIComponent(
search.trim().replace(/[\[\]\/\{\}\(\)\*\?\.\\\^\$\|]/g, '\\$&') //eslint-disable-line
)}`
: `&only-roots=false&_text=${encodeURIComponent(
search.trim().replace(/[\[\]\/\{\}\(\)\*\?\.\\\^\$\|]/g, '\\$&') //eslint-disable-line
)}*`
searchParam = `&only-roots=false&${noStar ? 'code' : '_tag=text-search-rank&_text'}=${encodeURIComponent(
search.trim()
)}`
}
// TODO test if it returns all the codes without specifying the count
const res = await apiFhir.get<FHIR_Bundle_Response<ValueSet>>(`/ValueSet?reference=${codeSystem}${searchParam}`, {
Expand Down
10 changes: 0 additions & 10 deletions src/services/aphp/cohortCreation/fetchObservation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@ export const fetchBiologySearch = async (
const res = await apiFhir.get<FHIR_Bundle_Response<ConceptMap>>(
`/ConceptMap?_count=2000&name=Maps%20to,Concept%20Fhir%20Maps%20To&source-system=${BIOLOGY_HIERARCHY_ITM_ANABIO}&target-system=${BIOLOGY_HIERARCHY_ITM_ANABIO},${BIOLOGY_HIERARCHY_ITM_LOINC}&_text=${encodeURIComponent(
lowerCaseTrimmedSearchInput.replace(/[\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&') // eslint-disable-line
)},${encodeURIComponent(
`/(.)*${lowerCaseTrimmedSearchInput.replace(/[/"]/g, function (m) {
switch (m) {
case '/':
return '\\/'
case '"':
return '\\"'
}
return m
})}(.)*/`
)}`
)

Expand Down
12 changes: 1 addition & 11 deletions src/services/aphp/serviceCohorts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,16 +331,6 @@ const servicesCohorts: IServiceCohorts = {
signal
) => {
try {
let _searchInput: string | string[] = ''
_searchInput = searchInput
.trim() // Remove space before/after search
.split(' ') // Split by space (= ['mot1', 'mot2' ...])
.filter((elem: string) => elem) // Filter if you have ['mot1', '', 'mot2'] (double space)

if (searchBy === SearchByTypes.IDENTIFIER) {
_searchInput = _searchInput.join()
}

// convert birthdates into days or months depending of if it's a deidentified perimeter or not
const birthdates: [string, string] = [
moment(substructAgeString(filters?.birthdatesRanges?.[0] || '')).format('MM/DD/YYYY'),
Expand All @@ -359,7 +349,7 @@ const servicesCohorts: IServiceCohorts = {
_list: groupId ? [groupId] : [],
gender: filters && filters.genders.join(','),
searchBy,
_text: _searchInput,
_text: searchInput.trim(),
minBirthdate: minBirthdate,
maxBirthdate: maxBirthdate,
deceased:
Expand Down
4 changes: 1 addition & 3 deletions src/state/patient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ const fetchPmsi = createAsyncThunk<FetchPmsiReturn, FetchPmsiParams, { state: Ro
const patientState = thunkApi.getState().patient
const index = mapToAttribute(options.selectedTab)
const currentPmsiState = patientState?.pmsi ? patientState?.pmsi[index] ?? { total: null } : { total: null }
const WILDCARD = '*'

const patientId = patientState?.patientInfo?.id ?? ''
if (!patientId) {
Expand All @@ -127,8 +126,7 @@ const fetchPmsi = createAsyncThunk<FetchPmsiReturn, FetchPmsiParams, { state: Ro
const sortBy = options.searchCriterias.orderBy.orderBy
const sortDirection = options.searchCriterias.orderBy.orderDirection
const page = options.page ?? 1
const searchInput =
options.searchCriterias.searchInput === '' ? '' : options.searchCriterias.searchInput + WILDCARD
const searchInput = options.searchCriterias.searchInput === '' ? '' : options.searchCriterias.searchInput
const codeUrl =
selectedTab === ResourceType.CLAIM
? CLAIM_HIERARCHY
Expand Down

0 comments on commit 9094ed3

Please sign in to comment.