Skip to content

Commit

Permalink
feat: added prescription end date - Ref gestion-de-projet#2681 (#1022)
Browse files Browse the repository at this point in the history
  • Loading branch information
ManelleG authored Jul 24, 2024
1 parent 581b9c1 commit 7fbeb70
Show file tree
Hide file tree
Showing 16 changed files with 140 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ import { Hierarchy } from 'types/hierarchy'
import { ScopeElement } from 'types'
import CalendarRange from 'components/ui/Inputs/CalendarRange'

import {
CriteriaType,
CriteriaTypesWithAdvancedInputs,
SelectedCriteriaTypesWithAdvancedInputs
} from 'types/requestCriterias'
import { CriteriaType, SelectedCriteriaTypesWithAdvancedInputs } from 'types/requestCriterias'
import { BlockWrapper } from 'components/ui/Layout'
import { DurationRangeType } from 'types/searchCriterias'
import { CriteriaLabel } from 'components/ui/CriteriaLabel'
import { getOccurenceDateLabel } from 'utils/requestCriterias'

type AdvancedInputsProps = {
sourceType: SourceType
Expand All @@ -31,8 +28,10 @@ type AdvancedInputsProps = {
const AdvancedInputs = ({ sourceType, selectedCriteria, onChangeValue, onError }: AdvancedInputsProps) => {
const optionsIsUsed =
(selectedCriteria.encounterService && selectedCriteria.encounterService.length > 0) ||
!!selectedCriteria.startOccurrence ||
!!selectedCriteria.endOccurrence ||
selectedCriteria.startOccurrence?.[0] !== null ||
selectedCriteria.startOccurrence?.[1] !== null ||
selectedCriteria.endOccurrence?.[0] !== null ||
selectedCriteria.endOccurrence?.[1] !== null ||
selectedCriteria.encounterStartDate[0] !== null ||
selectedCriteria.encounterStartDate[1] !== null ||
selectedCriteria.encounterEndDate[0] !== null ||
Expand All @@ -44,22 +43,6 @@ const AdvancedInputs = ({ sourceType, selectedCriteria, onChangeValue, onError }
onChangeValue('encounterService', _selectedExecutiveUnits)
}

const getOccurenceDateLabel = (
selectedCriteriaType: Exclude<CriteriaTypesWithAdvancedInputs, CriteriaType.IMAGING>
) => {
const mapping = {
[CriteriaType.DOCUMENTS]: 'Date de création du document',
[CriteriaType.CONDITION]: 'Date du diagnostic CIM10',
[CriteriaType.PROCEDURE]: "Date de l'acte CCAM",
[CriteriaType.CLAIM]: 'Date du classement en GHM',
[CriteriaType.MEDICATION_REQUEST]: 'Date de prescription',
[CriteriaType.MEDICATION_ADMINISTRATION]: "Date de début d'administration",
[CriteriaType.OBSERVATION]: "Date de l'examen"
}

return mapping[selectedCriteriaType]
}

return (
<Grid container direction="column">
<Grid
Expand Down Expand Up @@ -132,18 +115,32 @@ const AdvancedInputs = ({ sourceType, selectedCriteria, onChangeValue, onError }
</BlockWrapper>

{selectedCriteria.type !== CriteriaType.IMAGING && (
<BlockWrapper style={{ margin: '1em 1em 2em', width: 'calc(100% - 2em)' }}>
<CriteriaLabel>{getOccurenceDateLabel(selectedCriteria.type)}</CriteriaLabel>
<CalendarRange
inline
value={[selectedCriteria?.startOccurrence, selectedCriteria?.endOccurrence]}
onChange={([start, end]) => {
onChangeValue('startOccurrence', start)
onChangeValue('endOccurrence', end)
}}
onError={(isError) => onError(isError)}
/>
</BlockWrapper>
<>
<BlockWrapper style={{ margin: '1em 1em 2em', width: 'calc(100% - 2em)' }}>
<CriteriaLabel>{getOccurenceDateLabel(selectedCriteria.type)}</CriteriaLabel>
<CalendarRange
inline
value={selectedCriteria?.startOccurrence}
onChange={(newDate) => {
onChangeValue('startOccurrence', newDate)
}}
onError={(isError) => onError(isError)}
/>
</BlockWrapper>
{selectedCriteria.type === CriteriaType.MEDICATION_REQUEST && (
<BlockWrapper style={{ margin: '1em 1em 2em', width: 'calc(100% - 2em)' }}>
<CriteriaLabel>{getOccurenceDateLabel(selectedCriteria.type, true)}</CriteriaLabel>
<CalendarRange
inline
value={selectedCriteria?.endOccurrence ?? [null, null]}
onChange={(newDate) => {
onChangeValue('endOccurrence', newDate)
}}
onError={(isError) => onError(isError)}
/>
</BlockWrapper>
)}
</>
)}
</Collapse>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ export const defaultBiology: Omit<ObservationDataType, 'id'> = {
searchByValue: [null, null],
occurrence: 1,
occurrenceComparator: Comparators.GREATER_OR_EQUAL,
startOccurrence: '',
endOccurrence: '',
startOccurrence: [null, null],
isInclusive: true,
encounterStartDate: [null, null],
encounterEndDate: [null, null],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ export const defaultProcedure: Omit<CcamDataType, 'id'> = {
occurrence: 1,
hierarchy: undefined,
occurrenceComparator: Comparators.GREATER_OR_EQUAL,
startOccurrence: '',
endOccurrence: '',
startOccurrence: [null, null],
isInclusive: true,
encounterStartDate: [null, null],
encounterEndDate: [null, null],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ export const defaultCondition: Omit<Cim10DataType, 'id'> = {
diagnosticType: [],
occurrence: 1,
occurrenceComparator: Comparators.GREATER_OR_EQUAL,
startOccurrence: '',
endOccurrence: '',
startOccurrence: [null, null],
isInclusive: true,
encounterStartDate: [null, null],
encounterEndDate: [null, null],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ const defaultComposition: Omit<DocumentDataType, 'id'> = {
encounterEndDate: [null, null],
includeEncounterStartDateNull: false,
includeEncounterEndDateNull: false,
startOccurrence: '',
endOccurrence: '',
startOccurrence: [null, null],
isInclusive: true,
docStatuses: [],
encounterStatus: []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ const EncounterForm = ({
occurrence,
occurrenceComparator,
encounterStatus,
startOccurrence: [null, null],
isInclusive,
title,
type: CriteriaType.ENCOUNTER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ export const defaultClaim: Omit<GhmDataType, 'id'> = {
label: undefined,
occurrence: 1,
occurrenceComparator: Comparators.GREATER_OR_EQUAL,
startOccurrence: '',
endOccurrence: '',
startOccurrence: [null, null],
isInclusive: true,
encounterStartDate: [null, null],
encounterEndDate: [null, null],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ const HospitForm = ({
occurrenceComparator,
encounterStatus,
isInclusive,
startOccurrence: [null, null],
title
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ const ImagingForm: React.FC<CriteriaDrawerComponentProps> = (props) => {
includeEncounterStartDateNull,
encounterEndDate,
includeEncounterEndDateNull,
encounterStatus
encounterStatus,
startOccurrence: [null, null]
})
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react'
import React, { useEffect, useState } from 'react'

import {
Alert,
Expand Down Expand Up @@ -66,6 +66,12 @@ const MedicationForm: React.FC<MedicationFormProps> = (props) => {
)
const [error, setError] = useState(Error.NO_ERROR)

useEffect(() => {
if (currentState.type === CriteriaType.MEDICATION_ADMINISTRATION) {
onChangeValue('endOccurrence', [null, null])
}
}, [currentState.type])

const getMedicationOptions = async (searchValue: string, signal: AbortSignal) => {
const response = await services.cohortCreation.fetchMedicationData(searchValue, false, signal)
return response.map((elem) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export const defaultMedication: Omit<MedicationDataType, 'id'> = {
administration: [],
occurrence: 1,
occurrenceComparator: Comparators.GREATER_OR_EQUAL,
startOccurrence: '',
endOccurrence: '',
startOccurrence: [null, null],
endOccurrence: [null, null],
encounterEndDate: [null, null],
encounterStartDate: [null, null],
isInclusive: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ const PregnantForm = ({
encounterService,
occurrence,
occurrenceComparator,
startOccurrence: null,
endOccurrence: null,
startOccurrence: [null, null],
encounterStatus,
isInclusive,
title
Expand Down
1 change: 1 addition & 0 deletions src/mappers/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ 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',
Expand Down
4 changes: 2 additions & 2 deletions src/types/requestCriterias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ export type CommonCriteriaDataType = {
export type WithOccurenceCriteriaDataType = {
occurrence?: number | null
occurrenceComparator?: Comparators | null
startOccurrence?: string | null
endOccurrence?: string | null
startOccurrence: DurationRangeType
endOccurrence?: DurationRangeType
}

export type WithEncounterDateDataType = {
Expand Down
Loading

0 comments on commit 7fbeb70

Please sign in to comment.