From f9ab76a57da8f56b51f3fd0fb96b72d015db38cf Mon Sep 17 00:00:00 2001 From: Aykhan Ahmadli Date: Thu, 14 Nov 2024 19:30:04 +0100 Subject: [PATCH] Revert "Demo button upgrades" --- .../src/components/inputs/ProvidersSelect.tsx | 1 - .../src/helpers/create-sample-appointments.ts | 47 ++++--------------- .../app/src/hooks/useOttehrUser.tsx | 2 + .../app/src/pages/Appointments.tsx | 2 +- .../tracking-board/CreateDemoVisits.tsx | 11 +---- .../features/tracking-board/StateSelect.tsx | 3 -- .../tracking-board/TrackingBoardFilters.tsx | 2 + .../tracking-board/TrackingBoardTable.tsx | 8 ++-- .../tracking-board/TrackingBoardTabs.tsx | 2 +- packages/telemed-ehr/app/src/types/types.ts | 2 - .../zambdas/src/get-appointments/index.ts | 4 ++ .../zambdas/src/demo/example.spec.ts | 1 + .../zambdas/src/get-schedule/index.ts | 9 ++++ .../app/src/api/zapehrApi.ts | 2 + .../zambdas/src/shared/dateUtils.ts | 2 + 15 files changed, 39 insertions(+), 59 deletions(-) diff --git a/packages/telemed-ehr/app/src/components/inputs/ProvidersSelect.tsx b/packages/telemed-ehr/app/src/components/inputs/ProvidersSelect.tsx index 7c3402b6..f342c31d 100644 --- a/packages/telemed-ehr/app/src/components/inputs/ProvidersSelect.tsx +++ b/packages/telemed-ehr/app/src/components/inputs/ProvidersSelect.tsx @@ -18,7 +18,6 @@ export default function ProvidersSelect({ providers, practitioners, handleSubmit practitionerIDToName[practitioner.id] = formatHumanName(practitioner.name[0]); } }); - return ( => { try { if (!fhirClient) { @@ -63,7 +58,7 @@ export const createSampleAppointments = async ( for (let i = 0; i < 10; i++) { const visitService = appointmentTypes[i % 2]; - const randomPatientInfo = await generateRandomPatientInfo(fhirClient, visitService, user, phoneNumber); + const randomPatientInfo = await generateRandomPatientInfo(fhirClient, visitService, phoneNumber); const inputBody = JSON.stringify(randomPatientInfo); const response = await fetch(`${intakeZambdaUrl}/zambda/${createAppointmentZambdaId}/execute`, { @@ -88,7 +83,6 @@ export const createSampleAppointments = async ( const generateRandomPatientInfo = async ( fhirClient: FhirClient, visitService: 'in-person' | 'telemedicine', - user: User | undefined, phoneNumber?: string, ): Promise => { const firstNames = ['Alice', 'Bob', 'Charlie', 'Diana', 'Ethan', 'Fatima', 'Gabriel', 'Hannah', 'Ibrahim', 'Jake']; @@ -96,14 +90,11 @@ const generateRandomPatientInfo = async ( const sexes: PersonSex[] = [PersonSex.Male, PersonSex.Female, PersonSex.Intersex]; const searchParams: SearchParam[] = [{ name: 'status', value: 'active' }]; - - const allOffices: any[] = await fhirClient?.searchResources({ + const availableLocations: any[] = await fhirClient?.searchResources({ resourceType: 'Location', - searchParams: [{ name: '_count', value: '1000' }], + searchParams: searchParams, }); - const activeOffices = allOffices.filter((item) => item.status === 'active'); - const practitionersTemp: Practitioner[] = await fhirClient.searchResources({ resourceType: 'Practitioner', searchParams: [ @@ -119,26 +110,11 @@ const generateRandomPatientInfo = async ( .minus({ years: 7 + Math.floor(Math.random() * 16) }) .toISODate(); const randomSex = sexes[Math.floor(Math.random() * sexes.length)]; - const randomLocationIndex = Math.floor(Math.random() * activeOffices.length); - const randomLocationId = activeOffices[randomLocationIndex].id; + const randomLocationIndex = Math.floor(Math.random() * availableLocations.length); + const randomLocationId = availableLocations[randomLocationIndex].id; const randomProviderId = practitionersTemp[Math.floor(Math.random() * practitionersTemp.length)].id; - const selectedInPersonLocationID = localStorage.getItem('selectedLocationID'); - const selectedState = localStorage.getItem('selectedState'); - - const availableStates = - user?.profileResource && - allLicensesForPractitioner(user.profileResource).map((item) => { - return item.state; - }); - - const randomState = availableStates?.[Math.floor(Math.random() * availableStates.length)] || ''; - - const locationId = getLocationIdFromState(selectedState || randomState, allOffices); - - const isLocationActive = activeOffices.some((office) => office.id === locationId); - - const telemedLocationId = isLocationActive ? locationId : randomLocationId; + const selectedLocationID = localStorage.getItem('selectedLocationID'); if (visitService === 'telemedicine') { return { @@ -151,14 +127,14 @@ const generateRandomPatientInfo = async ( email: randomEmail, emailUser: 'Patient', }, - scheduleType: 'location', + scheduleType: 'provider', visitType: 'now', visitService: visitService, providerID: randomProviderId, timezone: 'UTC', isDemo: true, phoneNumber: phoneNumber, - locationID: telemedLocationId, + locationID: randomLocationId, }; } @@ -179,14 +155,9 @@ const generateRandomPatientInfo = async ( scheduleType: 'location', visitType: 'now', visitService: visitService, - locationID: selectedInPersonLocationID || randomLocationId, + locationID: selectedLocationID || randomLocationId, timezone: 'UTC', isDemo: true, phoneNumber: phoneNumber, }; }; - -const getLocationIdFromState = (state: string, allLocations: any[]): string | undefined => { - const location = allLocations.find((item) => item.address?.state === state); - return location?.id; -}; diff --git a/packages/telemed-ehr/app/src/hooks/useOttehrUser.tsx b/packages/telemed-ehr/app/src/hooks/useOttehrUser.tsx index ba6706c7..1cf4419b 100644 --- a/packages/telemed-ehr/app/src/hooks/useOttehrUser.tsx +++ b/packages/telemed-ehr/app/src/hooks/useOttehrUser.tsx @@ -125,6 +125,7 @@ export default function useOttehrUser(): OttehrUser | undefined { if (resourceType && resourceId && resourceType === 'Practitioner') { const practitioner = await client.readResource({ resourceType, resourceId }); useOttehrUserStore.setState({ profile: practitioner }); + console.log('practitioner', practitioner); } _profileLoadingState = LoadingState.idle; } catch (e) { @@ -346,6 +347,7 @@ const useGetProfile = () => { if (resourceType && resourceId && resourceType === 'Practitioner') { const practitioner = await fhirClient?.readResource({ resourceType, resourceId }); useOttehrUserStore.setState({ profile: practitioner }); + console.log('practitioner', practitioner); } } catch (e) { console.error(`error fetching user's fhir profile: ${JSON.stringify(e)}`); diff --git a/packages/telemed-ehr/app/src/pages/Appointments.tsx b/packages/telemed-ehr/app/src/pages/Appointments.tsx index ae77c996..32c614de 100644 --- a/packages/telemed-ehr/app/src/pages/Appointments.tsx +++ b/packages/telemed-ehr/app/src/pages/Appointments.tsx @@ -437,7 +437,7 @@ function AppointmentsBody(props: AppointmentsBodyProps): ReactElement { updateAppointments={updateAppointments} setEditingComment={setEditingComment} /> - + diff --git a/packages/telemed-ehr/app/src/telemed/features/tracking-board/CreateDemoVisits.tsx b/packages/telemed-ehr/app/src/telemed/features/tracking-board/CreateDemoVisits.tsx index cea7e252..8a1b12b9 100644 --- a/packages/telemed-ehr/app/src/telemed/features/tracking-board/CreateDemoVisits.tsx +++ b/packages/telemed-ehr/app/src/telemed/features/tracking-board/CreateDemoVisits.tsx @@ -8,13 +8,8 @@ import { useAuth0 } from '@auth0/auth0-react'; import { otherColors } from '../../../CustomThemeProvider'; import { LoadingButton } from '@mui/lab'; import { Box } from '@mui/system'; -import useOttehrUser from '../../../hooks/useOttehrUser'; -interface CreateDemoVisitsProps { - schedulePage?: 'telemedicine' | 'in-person'; -} - -const CreateDemoVisits = ({ schedulePage }: CreateDemoVisitsProps): ReactElement => { +const CreateDemoVisits = (): ReactElement => { const [phoneNumber, setPhoneNumber] = useState(''); const [inputError, setInputError] = useState(false); const [loading, setLoading] = useState(false); @@ -29,7 +24,6 @@ const CreateDemoVisits = ({ schedulePage }: CreateDemoVisitsProps): ReactElement }); const { fhirClient } = useApiClients(); const { getAccessTokenSilently } = useAuth0(); - const user = useOttehrUser(); const handleCreateSampleAppointments = async ( event: React.MouseEvent | React.FormEvent, @@ -46,13 +40,12 @@ const CreateDemoVisits = ({ schedulePage }: CreateDemoVisitsProps): ReactElement setLoading(true); setInputError(false); const authToken = await getAccessTokenSilently(); - const response = await createSampleAppointments(fhirClient, authToken, formattedPhoneNumber, user); + const response = await createSampleAppointments(fhirClient, authToken, formattedPhoneNumber); setSnackbar({ open: true, message: 'Appointments created successfully!', severity: 'success', }); - return response; } catch (error) { setSnackbar({ open: true, diff --git a/packages/telemed-ehr/app/src/telemed/features/tracking-board/StateSelect.tsx b/packages/telemed-ehr/app/src/telemed/features/tracking-board/StateSelect.tsx index 403bf8d1..9404558d 100644 --- a/packages/telemed-ehr/app/src/telemed/features/tracking-board/StateSelect.tsx +++ b/packages/telemed-ehr/app/src/telemed/features/tracking-board/StateSelect.tsx @@ -9,10 +9,7 @@ export function StateSelect(): ReactElement { const { availableStates, state } = getSelectors(useTrackingBoardStore, ['availableStates', 'state']); const options = [EMPTY_STATE, ...availableStates.map((state) => ({ label: state, value: state }))]; - const randomState = availableStates[Math.floor(Math.random() * availableStates.length)]; - const handleStateChange = (_e: any, { value }: { label: string | null; value: string | null }): void => { - localStorage.setItem('selectedState', value || ''); useTrackingBoardStore.setState((prevState) => ({ ...prevState, state: value })); }; diff --git a/packages/telemed-ehr/app/src/telemed/features/tracking-board/TrackingBoardFilters.tsx b/packages/telemed-ehr/app/src/telemed/features/tracking-board/TrackingBoardFilters.tsx index 3bbdc83a..a41a29c8 100644 --- a/packages/telemed-ehr/app/src/telemed/features/tracking-board/TrackingBoardFilters.tsx +++ b/packages/telemed-ehr/app/src/telemed/features/tracking-board/TrackingBoardFilters.tsx @@ -85,10 +85,12 @@ export const TrackingBoardFilters: FC<{ tab: ApptTab }> = (props) => { const useDate = tab === ApptTab.complete; const useUnsigned = tab === ApptTab['not-signed']; const handleProviderChange = (_e: any, value: string[]): void => { + console.log(10, value); setProviders(value); useTrackingBoardStore.setState({ providers: value }); }; const handleGroupChange = (_e: any, value: string[]): void => { + console.log(10, value); setGroups(value); useTrackingBoardStore.setState({ groups: value }); }; diff --git a/packages/telemed-ehr/app/src/telemed/features/tracking-board/TrackingBoardTable.tsx b/packages/telemed-ehr/app/src/telemed/features/tracking-board/TrackingBoardTable.tsx index e7e3e60c..cb7e9272 100644 --- a/packages/telemed-ehr/app/src/telemed/features/tracking-board/TrackingBoardTable.tsx +++ b/packages/telemed-ehr/app/src/telemed/features/tracking-board/TrackingBoardTable.tsx @@ -42,11 +42,11 @@ export function TrackingBoardTable({ tab }: AppointmentTableProps): ReactElement return {}; } return filteredAppointments.reduce>((accumulator, appointment) => { - if (appointment.location.state) { - if (!accumulator[appointment.location.state]) { - accumulator[appointment.location.state] = []; + if (appointment.location.locationID) { + if (!accumulator[appointment.location.locationID]) { + accumulator[appointment.location.locationID] = []; } - accumulator[appointment.location.state].push(appointment); + accumulator[appointment.location.locationID].push(appointment); return accumulator; } else if (appointment.provider) { if (!accumulator[appointment.provider.join(',')]) { diff --git a/packages/telemed-ehr/app/src/telemed/features/tracking-board/TrackingBoardTabs.tsx b/packages/telemed-ehr/app/src/telemed/features/tracking-board/TrackingBoardTabs.tsx index 4219c20b..fabb750b 100644 --- a/packages/telemed-ehr/app/src/telemed/features/tracking-board/TrackingBoardTabs.tsx +++ b/packages/telemed-ehr/app/src/telemed/features/tracking-board/TrackingBoardTabs.tsx @@ -63,7 +63,7 @@ export function TrackingBoardTabs(): ReactElement { - + ); diff --git a/packages/telemed-ehr/app/src/types/types.ts b/packages/telemed-ehr/app/src/types/types.ts index 16af1f72..bbc1d83f 100644 --- a/packages/telemed-ehr/app/src/types/types.ts +++ b/packages/telemed-ehr/app/src/types/types.ts @@ -112,8 +112,6 @@ export const AllStates = [ export type StateType = (typeof AllStates extends readonly (infer TElementType)[] ? TElementType : never)['value']; -export const AllStatesValues: StateType[] = AllStates.map(({ value }) => value); - export const AllStatesToNames: { [value in StateType]: string; } = { diff --git a/packages/telemed-ehr/zambdas/src/get-appointments/index.ts b/packages/telemed-ehr/zambdas/src/get-appointments/index.ts index c121f855..a09bfca7 100644 --- a/packages/telemed-ehr/zambdas/src/get-appointments/index.ts +++ b/packages/telemed-ehr/zambdas/src/get-appointments/index.ts @@ -208,6 +208,9 @@ export const index = async (input: ZambdaInput): Promise }); const [activeEncounters, searchResultsForSelectedDate] = await Promise.all([encounterSearch, appointmentSearch]); console.timeEnd('get_active_encounters + get_appointment_data'); + // console.log(searchResultsForSelectedDate); + // console.log(appointmentSearchParams); + // console.log(1, searchResultsForSelectedDate); const encounterIds: string[] = []; const tempAppointmentDates = activeEncounters @@ -416,6 +419,7 @@ export const index = async (input: ZambdaInput): Promise console.time('structure_appointment_data'); let appointments: Appointment[] = []; if (visitType?.length > 0) { + console.log(1, allAppointments.length); appointments = allAppointments?.filter((appointment) => { return visitType?.includes(appointment.appointmentType?.text || ''); }); diff --git a/packages/telemed-intake/zambdas/src/demo/example.spec.ts b/packages/telemed-intake/zambdas/src/demo/example.spec.ts index 18e174c0..99537e68 100644 --- a/packages/telemed-intake/zambdas/src/demo/example.spec.ts +++ b/packages/telemed-intake/zambdas/src/demo/example.spec.ts @@ -150,6 +150,7 @@ export async function getUser( await page.waitForTimeout(3000); expect(await page.getByText('Code is invalid').isVisible()).toBeFalsy(); await page.waitForTimeout(500); + console.log(1, token); return token; } diff --git a/packages/telemed-intake/zambdas/src/get-schedule/index.ts b/packages/telemed-intake/zambdas/src/get-schedule/index.ts index 930b6482..48f72720 100644 --- a/packages/telemed-intake/zambdas/src/get-schedule/index.ts +++ b/packages/telemed-intake/zambdas/src/get-schedule/index.ts @@ -261,6 +261,7 @@ async function getSchedule( currentDayTemp = currentDayTemp.plus({ days: 1 }); } }); + console.log(1, slots); return { message: 'Successful reply', // reminder to fix item adress @@ -396,6 +397,13 @@ export const distributeTimeSlots = ( currentAppointments: Appointment[], slotLength: number, ): string[] => { + // console.log(1, startTime, capacity, openingTime, closingTime); + // const minutesToDistributeInHour = Math.min( + // 60, + // startTime.diff(openingTime, 'minutes').minutes, + // startTime.diff(closingTime, 'minutes').minutes + // ); + // adjust startTime if minutes are not 00 to get an accurate minutesToDistributeInHour const adjustedStart: DateTime = startTime.minute !== 0 ? startTime.minus({ minutes: startTime.minute }) : startTime; @@ -422,6 +430,7 @@ export const distributeTimeSlots = ( const tempRoundedTime = tempTime.set({ minute: tempUpdatedRoundedMinute, second: 0, millisecond: 0 }); tempTime = tempTime.plus({ minutes: minutesPerSlot }); const timesSlotIndex = tempRoundedTime.toISO() || ''; + // console.log(1, tempRoundedTime.toISO()); // Appointments are bookable an hour away from the current time if (tempRoundedTime < DateTime.now().setZone('UTC').plus({ hours: 1 })) { diff --git a/packages/urgent-care-intake/app/src/api/zapehrApi.ts b/packages/urgent-care-intake/app/src/api/zapehrApi.ts index ab2832a8..d80a2c14 100644 --- a/packages/urgent-care-intake/app/src/api/zapehrApi.ts +++ b/packages/urgent-care-intake/app/src/api/zapehrApi.ts @@ -311,6 +311,7 @@ class API { if (GET_PRESIGNED_FILE_URL == null || REACT_APP_IS_LOCAL == null) { throw new Error('get presigned file url environment variable could not be loaded'); } + console.log(1); const response = await zambdaClient?.invokePublicZambda({ zambdaId: GET_PRESIGNED_FILE_URL, payload: { @@ -319,6 +320,7 @@ class API { fileFormat, }, }); + console.log(1); const jsonToUse = chooseJson(response, REACT_APP_IS_LOCAL); return jsonToUse; diff --git a/packages/urgent-care-intake/zambdas/src/shared/dateUtils.ts b/packages/urgent-care-intake/zambdas/src/shared/dateUtils.ts index 3ede8fb7..2a674f77 100644 --- a/packages/urgent-care-intake/zambdas/src/shared/dateUtils.ts +++ b/packages/urgent-care-intake/zambdas/src/shared/dateUtils.ts @@ -79,6 +79,7 @@ export const distributeTimeSlots = ( closingTime: DateTime, currentAppointments: Appointment[], ): string[] => { + // console.log(1, startTime, capacity, openingTime, closingTime); const ROUND_MINUTES = 15; // const minutesToDistributeInHour = Math.min( @@ -113,6 +114,7 @@ export const distributeTimeSlots = ( const tempRoundedTime = tempTime.set({ minute: tempUpdatedRoundedMinute, second: 0, millisecond: 0 }); tempTime = tempTime.plus({ minutes: minutesPerSlot }); const timesSlotIndex = tempRoundedTime.toISO() || ''; + // console.log(1, tempRoundedTime.toISO()); // Appointments are bookable an hour away from the current time if (tempRoundedTime < DateTime.now().setZone('UTC').plus({ hours: 1 })) {