From 0e7ff8d892713ce340c1bf352265f1ccbe6cc727 Mon Sep 17 00:00:00 2001 From: paolo7 Date: Tue, 23 Jul 2024 14:53:41 +0100 Subject: [PATCH 1/2] When Recurrence is null, now it does not display 'no' in the Recurrence field. --- .../components/ExpandableContainer/components/FollowUps.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/EpisodeDetails/components/ExpandableContainer/components/FollowUps.tsx b/src/pages/EpisodeDetails/components/ExpandableContainer/components/FollowUps.tsx index ba3b91f..875bd0a 100644 --- a/src/pages/EpisodeDetails/components/ExpandableContainer/components/FollowUps.tsx +++ b/src/pages/EpisodeDetails/components/ExpandableContainer/components/FollowUps.tsx @@ -337,7 +337,7 @@ const FollowUps: FC<{ followUp?.recurrence ? option.label === 'Yes' : option.label === 'No' ) From ccf786b58de169118528935f7b0587056e7125df Mon Sep 17 00:00:00 2001 From: paolo7 Date: Tue, 30 Jul 2024 21:24:38 +0100 Subject: [PATCH 2/2] Added preferred hospital functionality --- src/api/patientsAPI/patientsAPI.tsx | 1 + src/hooks/api/patientHooks.ts | 18 ++++++++++++++- src/hooks/constants.ts | 1 + src/models/apiTypes.tsx | 6 +++++ .../PatientDirectory/PatientDirectory.tsx | 23 +++++++++++++------ 5 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/api/patientsAPI/patientsAPI.tsx b/src/api/patientsAPI/patientsAPI.tsx index 56ce223..ed7eda0 100644 --- a/src/api/patientsAPI/patientsAPI.tsx +++ b/src/api/patientsAPI/patientsAPI.tsx @@ -28,4 +28,5 @@ export default { request(METHODS.POST, '/patient-hospital-mappings/', { params }), dischargePatient: (params: DischargePayload) => request(METHODS.POST, `/discharges/`, { params }), followUpPatient: (params: FollowUpPayload) => request(METHODS.POST, `/follow-ups/`, { params }), + getPreferredHospital: () => request(METHODS.GET, '/preferred-hospital/retrieve_for_current_user/', {}), }; diff --git a/src/hooks/api/patientHooks.ts b/src/hooks/api/patientHooks.ts index a950bc8..386fbc3 100644 --- a/src/hooks/api/patientHooks.ts +++ b/src/hooks/api/patientHooks.ts @@ -17,7 +17,7 @@ import { PaginationParams, PatientAPI, PatientsPayload, - PatientsResponse, + PatientsResponse, PreferredHospital, RegisterEpisodePayload, RegisterPatientPayload, SurgeonsResponse, @@ -43,6 +43,22 @@ export const useGetHospitals = (params?: PaginationParams) => { ); }; +export const useGetPreferredHospital = () => { + return useQuery( + ReactQueryKeys.PreferredHospitalQuery, + async () => { + const { request } = patientsAPI.single.getPreferredHospital(); + return await request(); + }, + { + onError: (error) => { + console.error("Error fetching preferred hospital:", error); + }, + retry: false, + } + ); +}; + export const useGetHospital = (id: string) => { return useQuery( [ReactQueryKeys.HospitalsQuery, id], diff --git a/src/hooks/constants.ts b/src/hooks/constants.ts index d013897..3f75f71 100644 --- a/src/hooks/constants.ts +++ b/src/hooks/constants.ts @@ -3,4 +3,5 @@ export const ReactQueryKeys = { HospitalsQuery: 'hospitalsQuery', SurgeonsQuery: 'surgeonsQuery', EpisodesQuery: 'episodesQuery', + PreferredHospitalQuery: 'preferredHospital', }; diff --git a/src/models/apiTypes.tsx b/src/models/apiTypes.tsx index ab6534a..0a02c04 100644 --- a/src/models/apiTypes.tsx +++ b/src/models/apiTypes.tsx @@ -215,3 +215,9 @@ export type HospitalMappingPayload = { hospital_id: number; patient_hospital_id: string; }; + +export interface PreferredHospital { + hospital: { + id: number; + }; +} \ No newline at end of file diff --git a/src/pages/PatientDirectory/PatientDirectory.tsx b/src/pages/PatientDirectory/PatientDirectory.tsx index 8489c04..b7e17f7 100644 --- a/src/pages/PatientDirectory/PatientDirectory.tsx +++ b/src/pages/PatientDirectory/PatientDirectory.tsx @@ -1,11 +1,11 @@ /** @jsxImportSource @emotion/react */ -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useState, useRef } from 'react'; import { IconButton, Filter } from '@orfium/ictinus'; import { FilterOption } from '@orfium/ictinus/dist/components/Filter/types'; import { ReactComponent as SortIcon } from 'assets/PatientDirectory/sortIcon.svg'; import { PageWrapper, PageTitle } from 'common.style'; -import { useGetHospitals, useGetPatients } from 'hooks/api/patientHooks'; +import { useGetHospitals, useGetPatients, useGetPreferredHospital } from 'hooks/api/patientHooks'; import { getHospitalOptions } from 'pages/RegisterPatient/utils'; import { useHistory } from 'react-router'; import urls from 'routing/urls'; @@ -20,7 +20,6 @@ import { SortingOptionsType } from './types'; const PatientDirectory: React.FC<{ searchTerm?: string }> = ({ searchTerm }) => { const { isDesktop } = useResponsiveLayout(); const [hospitalId, setHospitalId] = useState(); - const [sortingOption, setSortingOption] = useState( (localStorage.getItem('sortingOption') as SortingOptionsType) || '-created_at' ); @@ -37,12 +36,22 @@ const PatientDirectory: React.FC<{ searchTerm?: string }> = ({ searchTerm }) => const { data: hospitals } = useGetHospitals({ offset: 0, limit: 100 }); + const { data: preferredHospital } = useGetPreferredHospital(); + + const isFirstLoad = useRef(true); + useEffect(() => { - if (hospitals) { - setHospitalId(hospitals?.results[0].id); - setSelectedOption(hospitals?.results[0].id); + if (hospitals && isFirstLoad.current) { + if (preferredHospital && preferredHospital.hospital) { + setHospitalId(preferredHospital.hospital.id); + setSelectedOption(preferredHospital.hospital.id); + isFirstLoad.current = false; + } else { + setHospitalId(hospitals?.results[0].id); + setSelectedOption(hospitals?.results[0].id); + } } - }, [hospitals]); + }, [hospitals, preferredHospital]); useEffect(() => { if (sortingOption) {