Skip to content

Commit

Permalink
fix: fix display digit when request failed or cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehdi-BOUYAHIA committed Jul 2, 2024
1 parent 57fa724 commit 52da4b7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 7 deletions.
14 changes: 13 additions & 1 deletion src/components/Patient/PatientMedication/PatientMedication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ const PatientMedication = ({ groupId }: PatientMedicationProps) => {
id: ResourceType.MEDICATION_REQUEST,
label: MedicationLabel.PRESCRIPTION
})
const [oldTabs, setOldTabs] = useState<TabType<
ResourceType.MEDICATION_ADMINISTRATION | ResourceType.MEDICATION_REQUEST,
MedicationLabel
> | null>(null)
const medicationTabs: TabType<
ResourceType.MEDICATION_ADMINISTRATION | ResourceType.MEDICATION_REQUEST,
MedicationLabel
Expand Down Expand Up @@ -137,6 +141,7 @@ const PatientMedication = ({ groupId }: PatientMedicationProps) => {
fetchMedication({
options: {
selectedTab: selectedTab.id,
oldTab: oldTabs ? oldTabs.id : null,
page,
searchCriterias: {
orderBy,
Expand Down Expand Up @@ -181,11 +186,13 @@ const PatientMedication = ({ groupId }: PatientMedicationProps) => {
setEncounterStatusList(encounterStatus)
}
fetch()
setOldTabs(selectedTab)
}, [])

useEffect(() => {
setLoadingStatus(LoadingStatus.IDDLE)
setPage(1)
setOldTabs(selectedTab)
}, [
searchInput,
nda,
Expand All @@ -200,13 +207,15 @@ const PatientMedication = ({ groupId }: PatientMedicationProps) => {

useEffect(() => {
setLoadingStatus(LoadingStatus.IDDLE)
setOldTabs(selectedTab)
}, [page])

useEffect(() => {
if (loadingStatus === LoadingStatus.IDDLE) {
controllerRef.current = cancelPendingRequest(controllerRef.current)
_fetchMedication()
}
setOldTabs(selectedTab)
}, [loadingStatus])

useEffect(() => {
Expand Down Expand Up @@ -272,7 +281,10 @@ const PatientMedication = ({ groupId }: PatientMedicationProps) => {
active={selectedTab}
onchange={(
value: TabType<ResourceType.MEDICATION_ADMINISTRATION | ResourceType.MEDICATION_REQUEST, MedicationLabel>
) => setSelectedTab(value)}
) => {
setOldTabs(selectedTab)
setSelectedTab(value)
}}
/>
</Grid>
<Grid container justifyContent="center" item xs={12} md={4}>
Expand Down
10 changes: 9 additions & 1 deletion src/components/Patient/PatientPMSI/PatientPMSI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const PatientPMSI = ({ groupId }: PatientPMSIProps) => {
id: ResourceType.CONDITION,
label: PMSILabel.DIAGNOSTIC
})
const [oldTabs, setOldTabs] = useState<PmsiTab | null>(null)
const PMSITabs: PmsiTabs = [
{ label: PMSILabel.DIAGNOSTIC, id: ResourceType.CONDITION },
{ label: PMSILabel.CCAM, id: ResourceType.PROCEDURE },
Expand Down Expand Up @@ -132,6 +133,7 @@ const PatientPMSI = ({ groupId }: PatientPMSIProps) => {
fetchPmsi({
options: {
selectedTab: selectedTab.id,
oldTab: oldTabs ? oldTabs.id : null,
page,
searchCriterias: {
orderBy,
Expand Down Expand Up @@ -168,20 +170,24 @@ const PatientPMSI = ({ groupId }: PatientPMSIProps) => {
/* empty */
}
}
setOldTabs(selectedTab)
getSavedFilters()
fetch()
}, [])

useEffect(() => {
setLoadingStatus(LoadingStatus.IDDLE)
setPage(1)
setOldTabs(selectedTab)
}, [searchInput, nda, code, startDate, endDate, diagnosticTypes, source, orderBy, executiveUnits, encounterStatus])

useEffect(() => {
setLoadingStatus(LoadingStatus.IDDLE)
setOldTabs(selectedTab)
}, [page])

useEffect(() => {
setOldTabs(selectedTab)
if (loadingStatus === LoadingStatus.IDDLE) {
controllerRef.current = cancelPendingRequest(controllerRef.current)
_fetchPMSI()
Expand Down Expand Up @@ -273,7 +279,9 @@ const PatientPMSI = ({ groupId }: PatientPMSIProps) => {
active={selectedTab}
onchange={(
value: TabType<ResourceType.CONDITION | ResourceType.PROCEDURE | ResourceType.CLAIM, PMSILabel>
) => setSelectedTab(value)}
) => {
setOldTabs(selectedTab), setSelectedTab(value)
}}
/>
</Grid>
<Grid item xs={12} md={12} lg={4} xl={4} container justifyContent="center">
Expand Down
4 changes: 2 additions & 2 deletions src/mappers/pmsi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function mapToAttribute(type: ResourceType) {

export function mapToLabel(
type: ResourceType.MEDICATION_ADMINISTRATION | ResourceType.MEDICATION_REQUEST
): 'administration(s)' | 'prescriptions'
): 'administration(s)' | 'prescription(s)'
export function mapToLabel(type: ResourceType.CONDITION | ResourceType.CLAIM | ResourceType.PROCEDURE): PMSILabel
export function mapToLabel(type: ResourceType) {
switch (type) {
Expand All @@ -50,6 +50,6 @@ export function mapToLabel(type: ResourceType) {
case ResourceType.MEDICATION_ADMINISTRATION:
return 'administration(s)'
case ResourceType.MEDICATION_REQUEST:
return 'prescriptions'
return 'prescription(s)'
}
}
19 changes: 16 additions & 3 deletions src/state/patient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export type PatientState = null | {
type FetchPmsiParams = {
options: {
selectedTab: ResourceType.CLAIM | ResourceType.PROCEDURE | ResourceType.CONDITION
oldTab: ResourceType.CLAIM | ResourceType.PROCEDURE | ResourceType.CONDITION | null
page: number
searchCriterias: SearchCriterias<PMSIFilters>
}
Expand All @@ -126,6 +127,7 @@ const fetchPmsi = createAsyncThunk<FetchPmsiReturn, FetchPmsiParams, { state: Ro
const deidentified = patientState?.deidentified ?? true
const hospits = patientState?.hospits?.list ?? []
const selectedTab = options.selectedTab
const oldTab = options.oldTab
const sortBy = options.searchCriterias.orderBy.orderBy
const sortDirection = options.searchCriterias.orderBy.orderDirection
const page = options.page ?? 1
Expand Down Expand Up @@ -175,7 +177,12 @@ const fetchPmsi = createAsyncThunk<FetchPmsiReturn, FetchPmsiParams, { state: Ro
const pmsiReturn = {
loading: false,
count: pmsiResponse.pmsiTotal ?? 0,
total: currentPmsiState?.total ?? pmsiResponse.pmsiTotal ?? 0,
total:
selectedTab === oldTab && currentPmsiState?.total !== null
? currentPmsiState?.total !== 0
? currentPmsiState?.total
: pmsiResponse.pmsiTotal
: pmsiResponse.pmsiTotal,
list: pmsiList,
page,
options
Expand Down Expand Up @@ -290,6 +297,7 @@ const fetchBiology = createAsyncThunk<FetchBiologyReturn, FetchBiologyParams, {
type FetchMedicationParams = {
options: {
selectedTab: ResourceType.MEDICATION_REQUEST | ResourceType.MEDICATION_ADMINISTRATION
oldTab: ResourceType.MEDICATION_REQUEST | ResourceType.MEDICATION_ADMINISTRATION | null
page: number
searchCriterias: SearchCriterias<MedicationFilters>
}
Expand All @@ -306,7 +314,7 @@ const fetchMedication = createAsyncThunk<
{ state: RootState; rejectValue: any }
>(
'patient/fetchMedication',
async ({ options, options: { selectedTab, page, searchCriterias }, groupId, signal }, thunkApi) => {
async ({ options, options: { selectedTab, oldTab, page, searchCriterias }, groupId, signal }, thunkApi) => {
try {
const patientState = thunkApi.getState().patient

Expand Down Expand Up @@ -361,7 +369,12 @@ const fetchMedication = createAsyncThunk<
const medicationReturn = {
loading: false,
count: medicationResponse.medicationTotal ?? 0,
total: currentMedicationState?.total ?? medicationResponse.medicationTotal ?? 0,
total:
selectedTab === oldTab && currentMedicationState?.total !== null
? currentMedicationState?.total !== 0
? currentMedicationState?.total
: medicationResponse.medicationTotal
: medicationResponse.medicationTotal,
list: medicationList,
page,
options
Expand Down

0 comments on commit 52da4b7

Please sign in to comment.