From 2737b5e41ac5d2b14d0e2cc398bdd28808945948 Mon Sep 17 00:00:00 2001 From: Paul Bui-Quang Date: Thu, 10 Oct 2024 17:21:33 +0200 Subject: [PATCH] refactor: remove servicePerimeter circular dependency --- src/mappers/filters.ts | 199 ++----------------------- src/services/aphp/callApi.ts | 12 +- src/services/aphp/servicePerimeters.ts | 1 - src/types/requestCriterias.ts | 130 ++++++++++++++++ src/types/searchCriterias.ts | 51 +++++++ src/utils/cohortCreation.ts | 28 ++-- src/utils/mappers.ts | 12 +- 7 files changed, 228 insertions(+), 205 deletions(-) diff --git a/src/mappers/filters.ts b/src/mappers/filters.ts index 6a43e936a..c8fb24e6c 100644 --- a/src/mappers/filters.ts +++ b/src/mappers/filters.ts @@ -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, @@ -20,8 +30,10 @@ import { PMSIFilters, LabelObject, GenericFilter, - FilterByDocumentStatus, - DocumentStatuses + mapDocumentStatusesToRequestParam, + mapGenderStatusToGenderCodes, + mapDocumentStatusesFromRequestParam, + mapGenderCodesToGenderStatus } from 'types/searchCriterias' import allDocTypesList from 'assets/docTypes.json' import { @@ -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' @@ -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 - : '' -} diff --git a/src/services/aphp/callApi.ts b/src/services/aphp/callApi.ts index 5fbf1c15d..292f91c66 100644 --- a/src/services/aphp/callApi.ts +++ b/src/services/aphp/callApi.ts @@ -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' diff --git a/src/services/aphp/servicePerimeters.ts b/src/services/aphp/servicePerimeters.ts index beba9d438..fc5c9736d 100644 --- a/src/services/aphp/servicePerimeters.ts +++ b/src/services/aphp/servicePerimeters.ts @@ -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 { diff --git a/src/types/requestCriterias.ts b/src/types/requestCriterias.ts index 0686f69cb..09b4f6133 100644 --- a/src/types/requestCriterias.ts +++ b/src/types/requestCriterias.ts @@ -2,6 +2,17 @@ import { ScopeElement, SimpleCodeType } from 'types' import { Hierarchy } from './hierarchy' import { DocumentAttachmentMethod, DurationRangeType, LabelObject, SearchByTypes } from './searchCriterias' +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' +} + export enum MedicationLabel { PRESCRIPTION = 'Prescription', ADMINISTRATION = 'Administration' @@ -26,6 +37,125 @@ export enum ResourceType { export type PMSIResourceTypes = ResourceType.CONDITION | ResourceType.PROCEDURE | ResourceType.CLAIM +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 CriteriaType { REQUEST = 'Request', IPP_LIST = 'IPPList', diff --git a/src/types/searchCriterias.ts b/src/types/searchCriterias.ts index 7e9b66b36..0eb962768 100644 --- a/src/types/searchCriterias.ts +++ b/src/types/searchCriterias.ts @@ -29,6 +29,40 @@ export enum GenderCodes { UNDETERMINED = 'i', NOT_SPECIFIED = 'NON RENSEIGNE' } + +export 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 + } +} + +export 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 enum GenderStatusLabel { MALE = 'Hommes', FEMALE = 'Femmes', @@ -129,6 +163,23 @@ export enum DocumentStatuses { FINAL = 'final', PRELIMINARY = 'preliminary' } + +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 + : '' +} + export enum FilterKeys { IPP = 'ipp', GENDERS = 'genders', diff --git a/src/utils/cohortCreation.ts b/src/utils/cohortCreation.ts index 8bd3c7da0..b95549737 100644 --- a/src/utils/cohortCreation.ts +++ b/src/utils/cohortCreation.ts @@ -38,7 +38,19 @@ import { GhmDataType, CcamDataType, HospitDataType, - SelectedCriteriaTypesWithOccurrences + SelectedCriteriaTypesWithOccurrences, + AdministrationParamsKeys, + ClaimParamsKeys, + ConditionParamsKeys, + DocumentsParamsKeys, + EncounterParamsKeys, + ImagingParamsKeys, + IppParamsKeys, + ObservationParamsKeys, + PatientsParamsKeys, + PrescriptionParamsKeys, + ProcedureParamsKeys, + QuestionnaireResponseParamsKeys } from 'types/requestCriterias' import { parseOccurence } from './valueComparator' import { parseDocumentAttachment } from './documentAttachment' @@ -74,20 +86,6 @@ import { hospitForm } from 'data/hospitData' import { editAllCriteria, editAllCriteriaGroup, pseudonimizeCriteria, buildCohortCreation } from 'state/cohortCreation' import { AppDispatch } from 'state' import { Hierarchy } from 'types/hierarchy' -import { - AdministrationParamsKeys, - ClaimParamsKeys, - ConditionParamsKeys, - DocumentsParamsKeys, - EncounterParamsKeys, - ImagingParamsKeys, - IppParamsKeys, - ObservationParamsKeys, - PatientsParamsKeys, - PrescriptionParamsKeys, - ProcedureParamsKeys, - QuestionnaireResponseParamsKeys -} from 'mappers/filters' import { getConfig } from 'config' const REQUETEUR_VERSION = 'v1.6.0' diff --git a/src/utils/mappers.ts b/src/utils/mappers.ts index 454eb2163..9dbed36be 100644 --- a/src/utils/mappers.ts +++ b/src/utils/mappers.ts @@ -1,5 +1,10 @@ import { ScopeElement, SimpleCodeType } from 'types' -import { DocumentAttachmentMethod, DurationRangeType, LabelObject } from 'types/searchCriterias' +import { + DocumentAttachmentMethod, + DurationRangeType, + LabelObject, + mapDocumentStatusesFromRequestParam +} from 'types/searchCriterias' import { convertDurationToString, convertDurationToTimestamp, @@ -17,13 +22,14 @@ import { ObservationDataType, SelectedCriteriaTypesWithOccurrences, SelectedCriteriaTypesWithAdvancedInputs, - EncounterDataType + EncounterDataType, + EncounterParamsKeys, + ObservationParamsKeys } from 'types/requestCriterias' import { comparatorToFilter, parseOccurence } from './valueComparator' import services from 'services/aphp' import extractFilterParams, { FhirFilterValue } from './fhirFilterParser' import { Hierarchy } from 'types/hierarchy' -import { EncounterParamsKeys, ObservationParamsKeys, mapDocumentStatusesFromRequestParam } from 'mappers/filters' const searchReducer = (accumulator: string, currentValue: string): string => accumulator || !!accumulator === false ? `${accumulator},${currentValue}` : currentValue || accumulator