Skip to content

Commit

Permalink
refactor: remove servicePerimeter circular dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
pl-buiquang committed Oct 10, 2024
1 parent 68551c5 commit 2737b5e
Show file tree
Hide file tree
Showing 7 changed files with 228 additions and 205 deletions.
199 changes: 16 additions & 183 deletions src/mappers/filters.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import { ResourceType } from 'types/requestCriterias'
import {
AdministrationParamsKeys,
ClaimParamsKeys,
ConditionParamsKeys,
DocumentsParamsKeys,
ImagingParamsKeys,
ObservationParamsKeys,
PatientsParamsKeys,
PrescriptionParamsKeys,
ProcedureParamsKeys,
ResourceType
} from 'types/requestCriterias'
import { ScopeElement, SimpleCodeType } from 'types'
import {
Direction,
Filters,
GenderCodes,
GenderStatus,
Order,
PatientsFilters,
SearchBy,
Expand All @@ -20,8 +30,10 @@ import {
PMSIFilters,
LabelObject,
GenericFilter,
FilterByDocumentStatus,
DocumentStatuses
mapDocumentStatusesToRequestParam,
mapGenderStatusToGenderCodes,
mapDocumentStatusesFromRequestParam,
mapGenderCodesToGenderStatus
} from 'types/searchCriterias'
import allDocTypesList from 'assets/docTypes.json'
import {
Expand All @@ -37,136 +49,6 @@ import servicesPerimeters from 'services/aphp/servicePerimeters'
import { Hierarchy } from 'types/hierarchy'
import { getConfig } from 'config'

export enum PatientsParamsKeys {
GENDERS = 'gender',
DATE_DEIDENTIFIED = 'age-month',
DATE_IDENTIFIED = 'age-day',
VITAL_STATUS = 'deceased',
BIRTHDATE = 'birthdate',
DEATHDATE = 'death-date'
}

export enum EncounterParamsKeys {
DURATION = 'length',
MIN_BIRTHDATE_DAY = 'start-age-visit',
MIN_BIRTHDATE_MONTH = 'start-age-visit-month',
ENTRYMODE = 'admission-mode',
EXITMODE = 'discharge-disposition-mode',
PRISENCHARGETYPE = 'class',
TYPEDESEJOUR = 'stay',
ADMISSIONMODE = 'reason-code',
REASON = 'admission-destination-type',
DESTINATION = 'discharge-disposition',
PROVENANCE = 'admit-source',
ADMISSION = 'admission-type',
SERVICE_PROVIDER = 'encounter-care-site',
STATUS = 'status',
START_DATE = 'period-start',
END_DATE = 'period-end'
}

export enum DocumentsParamsKeys {
IPP = 'subject.identifier',
DOC_STATUSES = 'docstatus',
DOC_TYPES = 'type',
ONLY_PDF_AVAILABLE = 'onlyPdfAvailable',
NDA = 'encounter.identifier',
DATE = 'date',
EXECUTIVE_UNITS = 'encounter.encounter-care-site',
ENCOUNTER_STATUS = 'encounter.status'
}

export enum ConditionParamsKeys {
NDA = 'encounter.identifier',
CODE = 'code',
DIAGNOSTIC_TYPES = 'orbis-status',
DATE = 'recorded-date',
EXECUTIVE_UNITS = 'encounter.encounter-care-site',
SOURCE = '_source',
ENCOUNTER_STATUS = 'encounter.status',
IPP = 'subject.identifier'
}

export enum ProcedureParamsKeys {
NDA = 'encounter.identifier',
CODE = 'code',
SOURCE = '_source',
DATE = 'date',
EXECUTIVE_UNITS = 'encounter.encounter-care-site',
ENCOUNTER_STATUS = 'encounter.status',
IPP = 'subject.identifier'
}

export enum ClaimParamsKeys {
NDA = 'encounter.identifier',
CODE = 'diagnosis',
DATE = 'created',
EXECUTIVE_UNITS = 'encounter.encounter-care-site',
ENCOUNTER_STATUS = 'encounter.status',
IPP = 'patient.identifier'
}

export enum PrescriptionParamsKeys {
NDA = 'encounter.identifier',
PRESCRIPTION_TYPES = 'category',
DATE = 'validity-period-start',
END_DATE = 'validity-period-end',
CODE = 'code',
EXECUTIVE_UNITS = 'encounter.encounter-care-site',
ENCOUNTER_STATUS = 'encounter.status',
PRESCRIPTION_ROUTES = 'dosage-instruction-route'
}

export enum AdministrationParamsKeys {
NDA = 'context.identifier',
ADMINISTRATION_ROUTES = 'dosage-route',
DATE = 'effective-time',
EXECUTIVE_UNITS = 'context.encounter-care-site',
ENCOUNTER_STATUS = 'context.status'
}

export enum ObservationParamsKeys {
NDA = 'encounter.identifier',
ANABIO_LOINC = 'code',
VALIDATED_STATUS = 'status',
DATE = 'date',
VALUE = 'value-quantity',
EXECUTIVE_UNITS = 'encounter.encounter-care-site',
ENCOUNTER_STATUS = 'encounter.status',
IPP = 'subject.identifier'
}

export enum ImagingParamsKeys {
IPP = 'patient.identifier',
MODALITY = 'modality',
NDA = 'encounter.identifier',
DATE = 'started',
STUDY_DESCRIPTION = 'description',
STUDY_PROCEDURE = 'procedureCode',
NB_OF_SERIES = 'numberOfSeries',
NB_OF_INS = 'numberOfInstances',
WITH_DOCUMENT = 'with-document',
STUDY_UID = 'identifier',
SERIES_DATE = 'series-started',
SERIES_DESCRIPTION = 'series-description',
SERIES_PROTOCOL = 'series-protocol',
SERIES_MODALITIES = 'series-modality',
SERIES_UID = 'series',
EXECUTIVE_UNITS = 'encounter.encounter-care-site',
ENCOUNTER_STATUS = 'encounter.status'
}

export enum QuestionnaireResponseParamsKeys {
NAME = 'questionnaire.name',
DATE = 'authored',
EXECUTIVE_UNITS = 'encounter.encounter-care-site',
ENCOUNTER_STATUS = 'encounter.status'
}

export enum IppParamsKeys {
IPP_LIST_FHIR = 'identifier.value'
}

const getGenericKeyFromResourceType = (
type: ResourceType,
key: 'NDA' | 'DATE' | 'EXECUTIVE_UNITS' | 'ENCOUNTER_STATUS'
Expand Down Expand Up @@ -788,52 +670,3 @@ function mapBirthdatesRangesFromRequestParams(key: PatientsParamsKeys, parameter
})
return birthdatesRanges
}

function mapGenderStatusToGenderCodes(status: GenderStatus): GenderCodes {
switch (status) {
case GenderStatus.MALE:
return GenderCodes.MALE
case GenderStatus.FEMALE:
return GenderCodes.FEMALE
case GenderStatus.OTHER:
case GenderStatus.OTHER_UNKNOWN:
return GenderCodes.OTHER
case GenderStatus.UNKNOWN:
return GenderCodes.UNKNOWN
default:
return GenderCodes.NOT_SPECIFIED
}
}

function mapGenderCodesToGenderStatus(code: GenderCodes): GenderStatus {
switch (code) {
case GenderCodes.MALE:
return GenderStatus.MALE
case GenderCodes.FEMALE:
return GenderStatus.FEMALE
case GenderCodes.OTHER:
return GenderStatus.OTHER
case GenderCodes.UNKNOWN:
return GenderStatus.UNKNOWN
case GenderCodes.UNDETERMINED:
case GenderCodes.NOT_SPECIFIED:
default:
return GenderStatus.OTHER_UNKNOWN
}
}

export function mapDocumentStatusesToRequestParam(docStatus: string): string {
return docStatus === FilterByDocumentStatus.VALIDATED
? DocumentStatuses.FINAL
: docStatus === FilterByDocumentStatus.NOT_VALIDATED
? DocumentStatuses.PRELIMINARY
: ''
}

export function mapDocumentStatusesFromRequestParam(docStatus: string): string {
return docStatus === DocumentStatuses.FINAL
? FilterByDocumentStatus.VALIDATED
: docStatus === DocumentStatuses.PRELIMINARY
? FilterByDocumentStatus.NOT_VALIDATED
: ''
}
12 changes: 9 additions & 3 deletions src/services/aphp/callApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,26 @@ import {
import { getApiResponseResourceOrThrow, getApiResponseResourcesOrThrow } from 'utils/apiHelpers'
import { idSort, labelSort } from 'utils/alphabeticalSort'
import { capitalizeFirstLetter } from 'utils/capitalize'
import { Direction, Order, SavedFilter, SavedFiltersResults, SearchByTypes } from 'types/searchCriterias'
import {
Direction,
mapDocumentStatusesToRequestParam,
Order,
SavedFilter,
SavedFiltersResults,
SearchByTypes
} from 'types/searchCriterias'
import {
AdministrationParamsKeys,
ClaimParamsKeys,
ConditionParamsKeys,
DocumentsParamsKeys,
ImagingParamsKeys,
mapDocumentStatusesToRequestParam,
ObservationParamsKeys,
PatientsParamsKeys,
PrescriptionParamsKeys,
ProcedureParamsKeys,
QuestionnaireResponseParamsKeys
} from '../../mappers/filters'
} from 'types/requestCriterias'
import { ResourceType } from 'types/requestCriterias'
import { Hierarchy } from 'types/hierarchy'
import { getExtension } from 'utils/fhir'
Expand Down
1 change: 0 additions & 1 deletion src/services/aphp/servicePerimeters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { FetchScopeOptions, Rights, SourceType } from 'types/scope'
import { scopeLevelsToRequestParam } from 'utils/perimeters'
import { mapParamsToNetworkParams } from 'utils/url'
import { Hierarchy } from 'types/hierarchy'
import { Group } from 'fhir/r4'
import { getExtension } from 'utils/fhir'

export interface IServicePerimeters {
Expand Down
Loading

0 comments on commit 2737b5e

Please sign in to comment.