diff --git a/src/components/CreationCohort/DiagramView/components/LogicalOperator/components/CriteriaRightPanel/HospitForm/index.tsx b/src/components/CreationCohort/DiagramView/components/LogicalOperator/components/CriteriaRightPanel/HospitForm/index.tsx index c58dad08e..4a81ffe3a 100644 --- a/src/components/CreationCohort/DiagramView/components/LogicalOperator/components/CriteriaRightPanel/HospitForm/index.tsx +++ b/src/components/CreationCohort/DiagramView/components/LogicalOperator/components/CriteriaRightPanel/HospitForm/index.tsx @@ -277,7 +277,7 @@ const HospitForm = ({ onChangeIsInclusive={setIsInclusive} infoAlert={['Tous les éléments des champs multiples sont liés par une contrainte OU']} errorAlert={[ - error === Error.EMPTY_FORM ? "Merci de renseigner au moins un nombre d'occurence supérieur ou égal à 1" : '' + error === Error.EMPTY_FORM ? "Merci de renseigner au moins un nombre d'occurrence supérieur ou égal à 1" : '' ]} > diff --git a/src/components/CreationCohort/DiagramView/components/LogicalOperator/components/CriteriaRightPanel/PregnantForm/index.tsx b/src/components/CreationCohort/DiagramView/components/LogicalOperator/components/CriteriaRightPanel/PregnantForm/index.tsx index a210074fa..60d66b642 100644 --- a/src/components/CreationCohort/DiagramView/components/LogicalOperator/components/CriteriaRightPanel/PregnantForm/index.tsx +++ b/src/components/CreationCohort/DiagramView/components/LogicalOperator/components/CriteriaRightPanel/PregnantForm/index.tsx @@ -43,16 +43,16 @@ const PregnantForm = ({ criteria?.pregnancyStartDate || null ) const [pregnancyEndDate, setPregnancyEndDate] = useState( - criteria?.pregnancyStartDate || null + criteria?.pregnancyEndDate || null ) const [pregnancyMode, setPregnancyMode] = useState( mappingCriteria(criteria?.pregnancyMode, CriteriaDataKey.PREGNANCY_MODE, criteriaData) || [] ) - const [foetus, setFoetus] = useState(criteria?.foetus || 1) + const [foetus, setFoetus] = useState(criteria?.foetus || 0) const [foetusComparator, setFoetusComparator] = useState( criteria?.foetusComparator || Comparators.GREATER_OR_EQUAL ) - const [parity, setParity] = useState(criteria?.parity || 1) + const [parity, setParity] = useState(criteria?.parity || 0) const [parityComparator, setParityComparator] = useState( criteria?.parityComparator || Comparators.GREATER_OR_EQUAL ) @@ -155,7 +155,7 @@ const PregnantForm = ({ onChangeIsInclusive={setIsInclusive} infoAlert={['Tous les éléments des champs multiples sont liés par une contrainte OU']} errorAlert={[ - error === Error.EMPTY_FORM ? "Merci de renseigner au moins un nombre d'occurence supérieur ou égal à 1" : '' + error === Error.EMPTY_FORM ? "Merci de renseigner au moins un nombre d'occurrence supérieur ou égal à 1" : '' ]} > diff --git a/src/components/CreationCohort/DiagramView/components/TemporalConstraintCard/components/TemporalConstraintModal/StayConstraints.tsx b/src/components/CreationCohort/DiagramView/components/TemporalConstraintCard/components/TemporalConstraintModal/StayConstraints.tsx index a40c17095..98296a0c6 100644 --- a/src/components/CreationCohort/DiagramView/components/TemporalConstraintCard/components/TemporalConstraintModal/StayConstraints.tsx +++ b/src/components/CreationCohort/DiagramView/components/TemporalConstraintCard/components/TemporalConstraintModal/StayConstraints.tsx @@ -42,7 +42,7 @@ const StayConstraints: React.FC = ({ constraints, onChange const temporalConstraintsTypes = [ { id: TemporalConstraintsKind.NONE, - label: 'Aucune contrainte sur les épisodes' + label: 'Aucune contrainte sur les séjours' }, { id: TemporalConstraintsKind.SAME_ENCOUNTER, diff --git a/src/components/Patient/PatientForms/MaternityForms/HospitCard.tsx b/src/components/Patient/PatientForms/MaternityForms/HospitCard.tsx index 405e36bef..2b50bcb25 100644 --- a/src/components/Patient/PatientForms/MaternityForms/HospitCard.tsx +++ b/src/components/Patient/PatientForms/MaternityForms/HospitCard.tsx @@ -5,17 +5,39 @@ import { hospitForm } from 'data/hospitData' import moment from 'moment' import FormCards from 'components/ui/FormCard' import DomainAdd from '@mui/icons-material/DomainAdd' +import { QuestionnaireResponse, QuestionnaireResponseItemAnswer } from 'fhir/r4' interface HospitCardProps { form: CohortQuestionnaireResponse } const HospitCard: React.FC = ({ form }) => { + const getBirthDeliveryDate = ( + form: QuestionnaireResponse, + hospitForm: { + [key: string]: { + id: string + type: keyof QuestionnaireResponseItemAnswer + } + } + ) => { + const item = form.item?.find((item) => item.linkId === hospitForm.birthDeliveryStartDate.id) + return item ? `Accouchement le ${getDataFromForm(form, hospitForm.birthDeliveryStartDate)}` : undefined + } + + const formatHospitalisationDates = (start?: string, end?: string) => { + if (start && end) { + return `Hospitalisation du ${moment(start).format('DD/MM/YYYY')} au ${moment(end).format('DD/MM/YYYY')}` + } else if (start && !end) { + return `Début d'hospitalisation le ${moment(start).format('DD/MM/YYYY')}` + } + } + const hospitChipData = [ - form.item?.find((item) => item.linkId === hospitForm.birthDeliveryStartDate.id) - ? `Accouchement le ${getDataFromForm(form, hospitForm.birthDeliveryStartDate)}` - : `Date d'écriture : ${moment(form.authored).format('DD/MM/YYYY')}`, + getBirthDeliveryDate(form, hospitForm), + formatHospitalisationDates(form.hospitDates?.start, form.hospitDates?.end), `Unité exécutrice : ${form.serviceProvider}` - ] + ].filter((item): item is string => item !== undefined) + const hospitDetails = [ { name: "Motif d'hospitalisation", diff --git a/src/services/aphp/callApi.ts b/src/services/aphp/callApi.ts index 704babee2..8fd5295f8 100644 --- a/src/services/aphp/callApi.ts +++ b/src/services/aphp/callApi.ts @@ -893,7 +893,7 @@ type fetchFormsProps = { } export const fetchForms = async (args: fetchFormsProps) => { const { patient, formName, _list, startDate, endDate, executiveUnits } = args - let options: string[] = [] + let options: string[] = ['status=in-progress,completed'] if (patient) options = [...options, `subject=${patient}`] if (formName) options = [...options, `questionnaire.name=${formName}`] if (_list && _list.length > 0) options = [...options, `_list=${_list.reduce(paramValuesReducer)}`] diff --git a/src/state/patient.ts b/src/state/patient.ts index f0b054605..9a49caa95 100644 --- a/src/state/patient.ts +++ b/src/state/patient.ts @@ -1435,6 +1435,7 @@ function linkElementWithEncounter< serviceProvider?: string NDA?: string documents?: any[] + hospitDates?: string[] })[] = [] for (const entry of elementEntries) { @@ -1442,6 +1443,7 @@ function linkElementWithEncounter< serviceProvider?: string NDA?: string documents?: any[] + hospitDates?: string[] } let encounterId = '' @@ -1469,6 +1471,9 @@ function linkElementWithEncounter< case RessourceType.IMAGING: encounterId = (entry as ImagingStudy).encounter?.reference?.replace(/^Encounter\//, '') ?? '' break + case RessourceType.QUESTIONNAIRE_RESPONSE: + encounterId = entry.encounter?.reference?.replace(/^Encounter\//, '') ?? '' + break } const foundEncounter = encounterList.find(({ id }) => id === encounterId) || null @@ -1506,6 +1511,7 @@ function fillElementInformation< serviceProvider?: string NDA?: string documents?: any[] + hospitDates?: string[] } const encounterIsDetailed = encounter?.id !== encounterId @@ -1532,5 +1538,9 @@ function fillElementInformation< newElement.documents = encounter.documents } + if (resourceType === RessourceType.QUESTIONNAIRE_RESPONSE) { + newElement.hospitDates = encounter.period + } + return newElement } diff --git a/src/types.ts b/src/types.ts index a535e461d..42cd085db 100644 --- a/src/types.ts +++ b/src/types.ts @@ -15,6 +15,7 @@ import { OperationOutcome, Parameters, Patient, + Period, Procedure, QuestionnaireResponse, Resource @@ -657,6 +658,7 @@ export enum BiologyStatus { export type CohortQuestionnaireResponse = QuestionnaireResponse & { serviceProvider?: string NDA?: string + hospitDates?: Period } export type CohortObservation = Observation & { diff --git a/src/utils/cohortCreation.ts b/src/utils/cohortCreation.ts index b80330d19..a3a495fb9 100644 --- a/src/utils/cohortCreation.ts +++ b/src/utils/cohortCreation.ts @@ -408,6 +408,7 @@ const constructFilterFhir = (criterion: SelectedCriteriaType, deidentified: bool filterFhir = [ 'subject.active=true', `questionnaire.name=${FormNames.PREGNANCY}`, + 'status=in-progress,completed', questionnaireFiltersBuilders( pregnancyForm.pregnancyStartDate, buildDateFilter(criterion.pregnancyStartDate, 'ge', true) @@ -468,6 +469,7 @@ const constructFilterFhir = (criterion: SelectedCriteriaType, deidentified: bool filterFhir = [ 'subject.active=true', `questionnaire.name=${FormNames.HOSPIT}`, + 'status=in-progress,completed', questionnaireFiltersBuilders(hospitForm.hospitReason, buildSearchFilter(criterion.hospitReason)), questionnaireFiltersBuilders(hospitForm.inUteroTransfer, buildLabelObjectFilter(criterion.inUteroTransfer)), questionnaireFiltersBuilders( @@ -1386,9 +1388,9 @@ export async function unbuildRequest(_json: string): Promise { currentCriterion.pregnancyStartDate = null currentCriterion.pregnancyEndDate = null currentCriterion.pregnancyMode = [] - currentCriterion.foetus = 1 + currentCriterion.foetus = 0 currentCriterion.foetusComparator = Comparators.GREATER_OR_EQUAL - currentCriterion.parity = 1 + currentCriterion.parity = 0 currentCriterion.parityComparator = Comparators.GREATER_OR_EQUAL currentCriterion.maternalRisks = [] currentCriterion.maternalRisksPrecision = '' @@ -1411,10 +1413,11 @@ export async function unbuildRequest(_json: string): Promise { switch (key) { case pregnancyForm.pregnancyStartDate.id: - currentCriterion.pregnancyStartDate = unbuildDateFilter(singleValue) - break - case pregnancyForm.pregnancyEndDate.id: - currentCriterion.pregnancyEndDate = unbuildDateFilter(singleValue) + if (operator?.includes('ge')) { + currentCriterion.pregnancyStartDate = unbuildDateFilter(singleValue) + } else if (operator === 'le') { + currentCriterion.pregnancyEndDate = unbuildDateFilter(singleValue) + } break case pregnancyForm.pregnancyMode.id: unbuildLabelObjectFilter(currentCriterion, 'pregnancyMode', joinedValues) @@ -1587,10 +1590,11 @@ export async function unbuildRequest(_json: string): Promise { unbuildLabelObjectFilter(currentCriterion, 'analgesieType', joinedValues) break case hospitForm.birthDeliveryStartDate.id: - currentCriterion.birthDeliveryStartDate = unbuildDateFilter(singleValue) - break - case hospitForm.birthDeliveryEndDate.id: - currentCriterion.birthDeliveryEndDate = unbuildDateFilter(singleValue) + if (operator?.includes('ge')) { + currentCriterion.birthDeliveryStartDate = unbuildDateFilter(singleValue) + } else if (operator === 'le') { + currentCriterion.birthDeliveryEndDate = unbuildDateFilter(singleValue) + } break case hospitForm.birthDeliveryWeeks.id: { const _value = `${operator}${singleValue}` diff --git a/src/utils/requestCriterias.tsx b/src/utils/requestCriterias.tsx index f7d9bdc10..6d11b5f2a 100644 --- a/src/utils/requestCriterias.tsx +++ b/src/utils/requestCriterias.tsx @@ -378,11 +378,11 @@ export const criteriasAsArray = (selectedCriteria: SelectedCriteriaType, criteri ) ) } - if (!isNaN(selectedCriteria.foetus) && selectedCriteria.foetusComparator) + if (!isNaN(selectedCriteria.foetus) && selectedCriteria.foetusComparator && selectedCriteria.foetus !== 0) labels.push( getNbOccurencesLabel(selectedCriteria.foetus, selectedCriteria.foetusComparator, 'Nombre de foetus') ) - if (!isNaN(selectedCriteria.parity) && selectedCriteria.parityComparator) + if (!isNaN(selectedCriteria.parity) && selectedCriteria.parityComparator && selectedCriteria.parity !== 0) labels.push(getNbOccurencesLabel(selectedCriteria.parity, selectedCriteria.parityComparator, 'Parité')) if (selectedCriteria.maternalRisks && selectedCriteria.maternalRisks.length > 0) labels.push( @@ -859,7 +859,7 @@ export const criteriasAsArray = (selectedCriteria: SelectedCriteriaType, criteri getNbOccurencesLabel( selectedCriteria.occurrence, selectedCriteria.occurrenceComparator, - "Nombre d'occurences" + "Nombre d'occurrences" ) ) if (selectedCriteria.startOccurrence || selectedCriteria.endOccurrence)