Skip to content

Commit

Permalink
remove node libs usage from some utils package files, move auth relat…
Browse files Browse the repository at this point in the history
…ed functions that were brought out to utils back into individual zambda folders (cause soon zambdas packages will be unified), remove node types from ui apps components
  • Loading branch information
VladMstv committed Jan 27, 2025
1 parent 5406bf1 commit e06a17a
Show file tree
Hide file tree
Showing 52 changed files with 188 additions and 324 deletions.
6 changes: 6 additions & 0 deletions apps/intake/src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ declare module 'object.hasown' {
// eslint-disable-next-line @typescript-eslint/no-empty-function
export const shim = (): void => {};
}

declare global {
interface Window {
global: any;
}
}
6 changes: 3 additions & 3 deletions apps/intake/src/hooks/useSetLastActiveTime.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect } from 'react';
import { zapehrApi } from '../api';
import { DateTime } from 'luxon';
import { useEffect } from 'react';
import { ZambdaClient } from 'ui-components/lib/hooks/useUCZambdaClient';
import { zapehrApi } from '../api';

// Update last active time for paperwork-in-progress flag every minute
export function useSetLastActiveTime(
Expand All @@ -10,7 +10,7 @@ export function useSetLastActiveTime(
zambdaClient: ZambdaClient | null
): void {
useEffect(() => {
let interval: NodeJS.Timeout;
let interval: ReturnType<typeof setInterval>;
try {
if (zambdaClient && appointmentID && paperworkPage) {
interval = setInterval(async () => {
Expand Down
2 changes: 2 additions & 0 deletions apps/intake/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import App from './App';
import './index.css';
import './lib/i18n';

window.global ||= window; // https://stackoverflow.com/questions/72795666/how-to-fix-vite-build-parser-error-unexpected-token-in-third-party-dependenc

// polyfill for fixing missing hasOwn Object property in some browsers
// https://www.npmjs.com/package/object.hasown
if (!Object.hasOwn) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { FC, useCallback, useEffect, useRef, useState } from 'react';
import { Box, Card, FormControl, IconButton, InputLabel, MenuItem, Select, Typography } from '@mui/material';
import KeyboardVoiceOutlinedIcon from '@mui/icons-material/KeyboardVoiceOutlined';
import GraphicEqIcon from '@mui/icons-material/GraphicEq';
import KeyboardVoiceIcon from '@mui/icons-material/KeyboardVoice';
import ReplayIcon from '@mui/icons-material/Replay';
import PlayArrowIcon from '@mui/icons-material/PlayArrow';
import KeyboardVoiceOutlinedIcon from '@mui/icons-material/KeyboardVoiceOutlined';
import PauseIcon from '@mui/icons-material/Pause';
import PlayArrowIcon from '@mui/icons-material/PlayArrow';
import ReplayIcon from '@mui/icons-material/Replay';
import StopIcon from '@mui/icons-material/Stop';
import GraphicEqIcon from '@mui/icons-material/GraphicEq';
import { Box, Card, FormControl, IconButton, InputLabel, MenuItem, Select, Typography } from '@mui/material';
import { FC, useCallback, useEffect, useRef, useState } from 'react';
import { otherColors } from '../../../IntakeThemeProvider';

type MicrophoneSettingsProps = {
Expand Down Expand Up @@ -77,7 +77,7 @@ export const MicrophoneSettings: FC<MicrophoneSettingsProps> = (props) => {
}, [audioChunks]);

useEffect(() => {
let timeout: NodeJS.Timeout | null = null;
let timeout: ReturnType<typeof setTimeout> | null = null;
if (recordingStatus === 'recording') {
timeout = setTimeout(() => {
stopRecording();
Expand Down
8 changes: 3 additions & 5 deletions apps/intake/src/telemed/pages/VideoChatPage.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
window.global ||= window; // https://stackoverflow.com/questions/72795666/how-to-fix-vite-build-parser-error-unexpected-token-in-third-party-dependenc

import { Container } from '@mui/material';
import {
DeviceLabels,
GlobalStyles,
MeetingProvider,
lightTheme,
useMeetingManager,
useAudioInputs,
useAudioVideo,
useLocalVideo,
useAudioInputs,
useMeetingManager,
useVideoInputs,
} from 'amazon-chime-sdk-component-library-react';
import { MeetingSessionConfiguration } from 'amazon-chime-sdk-js';
Expand All @@ -21,7 +19,7 @@ import { intakeFlowPageRoute } from '../../App';
import { CallSideCard, LoadingSpinner } from '../components';
import { useAppointmentStore } from '../features/appointments';
import { CustomContainer, useIntakeCommonStore } from '../features/common';
import { VideoRoom, useJoinCall, useVideoCallStore, useCallSettingsStore } from '../features/video-call';
import { VideoRoom, useCallSettingsStore, useJoinCall, useVideoCallStore } from '../features/video-call';
import { useZapEHRAPIClient } from '../utils';

const VideoChatPage: FC = () => {
Expand Down
10 changes: 8 additions & 2 deletions packages/ehr/zambdas/scripts/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import {
Resource,
Substance,
} from 'fhir/r4b';
import { createOystehrClientFromSecrets, Secrets } from 'utils';
import { getAuth0Token } from '../src/shared';
import { createOystehrClient, Secrets } from 'utils';
import { getAuth0Token, getSecret, SecretsKeys } from '../src/shared';

export const fhirApiUrlFromAuth0Audience = (auth0Audience: string): string => {
switch (auth0Audience) {
Expand Down Expand Up @@ -209,3 +209,9 @@ export const createOystehrClientFromConfig = async (config: Secrets): Promise<Oy
if (!token) throw new Error('Failed to fetch auth token.');
return createOystehrClientFromSecrets(token, config);
};

function createOystehrClientFromSecrets(token: string, secrets: Secrets | null): Oystehr {
const FHIR_API = getSecret(SecretsKeys.FHIR_API, secrets).replace(/\/r4/g, '');
const PROJECT_API = getSecret(SecretsKeys.PROJECT_API, secrets);
return createOystehrClient(token, FHIR_API, PROJECT_API);
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { ZambdaInput } from '../types';
import { UpdateMedicationOrderInput } from 'utils';
import { ZambdaInput } from '../types';

export function validateRequestParameters(
input: ZambdaInput
): UpdateMedicationOrderInput & Pick<ZambdaInput, 'secrets'> {
console.group('validateRequestParameters');

// if (getSecret(SecretsKeys.PROJECT_API, input.secrets) === undefined) {
// throw new Error('"PROJECT_API" configuration not provided');
// }

if (!input.body) {
throw new Error('No request body provided');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { ZambdaInput } from '../types';
import { GetMedicationOrdersInput } from 'utils';
import { ZambdaInput } from '../types';

export function validateRequestParameters(input: ZambdaInput): GetMedicationOrdersInput & Pick<ZambdaInput, 'secrets'> {
console.group('validateRequestParameters');

// if (getSecret(SecretsKeys.PROJECT_API, input.secrets) === undefined) {
// throw new Error('"PROJECT_API" configuration not provided');
// }

if (!input.body) {
throw new Error('No request body provided');
}
Expand Down
4 changes: 2 additions & 2 deletions packages/ehr/zambdas/src/shared/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Secrets,
TELEMED_VIDEO_ROOM_CODE,
} from 'utils';
import { getAuth0Token as getM2MClientToken } from './getAuth0Token';
import { getAuth0Token } from './getAuth0Token';
import { SecretsKeys, getSecret } from './secrets';

export function createOystehrClient(token: string, secrets: Secrets | null): Oystehr {
Expand All @@ -26,7 +26,7 @@ export function createOystehrClient(token: string, secrets: Secrets | null): Oys
export async function checkOrCreateM2MClientToken(token: string, secrets: Secrets | null): Promise<string> {
if (!token) {
console.log('getting m2m token for service calls...');
return await getM2MClientToken(secrets);
return await getAuth0Token(secrets);
} else {
console.log('already have a token, no need to update');
}
Expand Down
15 changes: 7 additions & 8 deletions packages/intake/zambdas/src/appointment/get-past-visits/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import { APIGatewayProxyResult } from 'aws-lambda';
import { Appointment, Location, Patient } from 'fhir/r4b';
import {
GetPastVisitsResponse,
SecretsKeys,
AppointmentInformationIntake,
ZambdaInput,
AppointmentStatus,
appointmentTypeMap,
createOystehrClient,
getParticipantIdFromAppointment,
GetPastVisitsResponse,
getPatientsForUser,
getSecret,
mapStatusToTelemed,
appointmentTypeMap,
getVisitStatus,
AppointmentStatus,
mapStatusToTelemed,
ZambdaInput,
} from 'utils';
import { checkOrCreateM2MClientToken, getUser } from '../../shared';
import { mapEncountersToAppointmentIds, getFhirResources } from './helpers';
import { getSecret, SecretsKeys } from '../../shared/secrets';
import { getFhirResources, mapEncountersToAppointmentIds } from './helpers';
import { validateRequestParameters } from './validateRequestParameters';

// Lifting up value to outside of the handler allows it to stay in memory across warm lambda invocations
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import { APIGatewayProxyResult } from 'aws-lambda';
import {
createOystehrClient,
getEncounterForAppointment,
getSecret,
GetVisitDetailsResponse,
SecretsKeys,
ZambdaInput,
} from 'utils';
import { createOystehrClient, getEncounterForAppointment, GetVisitDetailsResponse, ZambdaInput } from 'utils';

import { checkOrCreateM2MClientToken } from '../../shared';
import { getSecret, SecretsKeys } from '../../shared/secrets';
import { getMedications, getPaymentDataRequest, getPresignedURLs } from './helpers';
import { validateRequestParameters } from './validateRequestParameters';

Expand Down
10 changes: 2 additions & 8 deletions packages/intake/zambdas/src/appointment/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import Oystehr from '@oystehr/sdk';
import { Coding, Extension, Questionnaire } from 'fhir/r4b';
import {
OtherParticipantsExtension,
Secrets,
SecretsKeys,
ServiceMode,
TELEMED_VIDEO_ROOM_CODE,
getSecret,
} from 'utils';
import { OtherParticipantsExtension, Secrets, ServiceMode, TELEMED_VIDEO_ROOM_CODE } from 'utils';
import { getSecret, SecretsKeys } from '../shared/secrets';

export const getCurrentQuestionnaireForServiceType = async (
serviceType: ServiceMode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
FHIR_ZAPEHR_URL,
POST_TELEMED_APPOINTMENT_CANT_BE_CANCELED_ERROR,
Secrets,
SecretsKeys,
ZambdaInput,
formatPhoneNumberDisplay,
getAppointmentResourceById,
Expand All @@ -23,7 +22,6 @@ import {
getPatientContactEmail,
getPatientFirstName,
getRelatedPersonForPatient,
getSecret,
isPostTelemedAppointment,
topLevelCatch,
} from 'utils';
Expand All @@ -35,6 +33,7 @@ import { AuditableZambdaEndpoints, createAuditEvent } from '../../shared/userAud
import { validateBundleAndExtractAppointment } from '../../shared/validateBundleAndExtractAppointment';
import { validateRequestParameters } from './validateRequestParameters';

import { SecretsKeys, getSecret } from '../../shared/secrets';
export interface CancelAppointmentInput {
appointmentID: string;
cancellationReason: CancellationReasonOptionsInPerson;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ import { DateTime } from 'luxon';
import {
APPOINTMENT_CANT_BE_IN_PAST_ERROR,
CreateAppointmentInputParams,
getSecret,
isISODateTime,
PersonSex,
Secrets,
SecretsKeys,
VisitType,
ZambdaInput,
} from 'utils';
import { SCHEDULE_TYPES } from '../../get-schedule/validateRequestParameters';
import { phoneRegex } from '../../shared';
import { checkValidBookingTime } from '../../shared/helpers';

import { getSecret, SecretsKeys } from '../../shared/secrets';
export interface CreateAppointmentValidatedInput
extends Omit<CreateAppointmentInputParams, 'providerID' | 'groupID' | 'locationID'> {
currentCanonicalQuestionnaireUrl: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,20 @@
import { BatchInputGetRequest } from '@oystehr/sdk';
import { APIGatewayProxyResult } from 'aws-lambda';
import { Operation } from 'fast-json-patch';
import { Appointment, Encounter, Location, Patient, HealthcareService, Practitioner } from 'fhir/r4b';
import { Appointment, Encounter, HealthcareService, Location, Patient, Practitioner } from 'fhir/r4b';
import { DateTime } from 'luxon';
import {
APPOINTMENT_NOT_FOUND_ERROR,
CancellationReasonOptionsTelemed,
FHIR_ZAPEHR_URL,
SLUG_SYSTEM,
Secrets,
SecretsKeys,
ZambdaInput,
cancelAppointmentResource,
createOystehrClient,
getAppointmentResourceById,
getPatchBinary,
getRelatedPersonForPatient,
getSecret,
} from 'utils';
import {
AuditableZambdaEndpoints,
Expand All @@ -27,10 +25,10 @@ import {
sendSms,
} from '../../shared';
import { sendVirtualCancellationEmail } from '../../shared/communication';
import { SecretsKeys, getSecret } from '../../shared/secrets';
import { validateBundleAndExtractAppointment } from '../../shared/validateBundleAndExtractAppointment';
import { getPatientContactEmail } from '../telemed-create-appointment';
import { validateRequestParameters } from './validateRequestParameters';

export interface CancelAppointmentInput {
appointmentID: string;
cancellationReason: CancellationReasonOptionsTelemed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ import {
createOystehrClient,
FHIR_EXTENSION,
formatPhoneNumber,
getSecret,
makePrepopulatedItemsForPatient,
OTTEHR_MODULE,
PatientInfo,
PRIVATE_EXTENSION_BASE_URL,
RequiredAllProps,
Secrets,
SecretsKeys,
ServiceMode,
topLevelCatch,
userHasAccessToPatient,
Expand All @@ -36,6 +34,7 @@ import {
} from 'utils';
import { AuditableZambdaEndpoints, checkOrCreateM2MClientToken, createAuditEvent, getUser } from '../../shared';
import { createUpdateUserRelatedResources, generatePatientRelatedRequests } from '../../shared/appointment';
import { getSecret, SecretsKeys } from '../../shared/secrets';
import {
getCurrentQuestionnaireForServiceType,
getEncounterClass,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { APIGatewayProxyResult } from 'aws-lambda';
import { Appointment, Location, Patient } from 'fhir/r4b';
import {
GetTelemedAppointmentsResponse,
SecretsKeys,
TelemedAppointmentInformationIntake,
ZambdaInput,
createOystehrClient,
getParticipantIdFromAppointment,
getPatientsForUser,
getSecret,
GetTelemedAppointmentsResponse,
mapStatusToTelemed,
TelemedAppointmentInformationIntake,
ZambdaInput,
} from 'utils';
import { checkOrCreateM2MClientToken, getUser } from '../../shared';
import { getSecret, SecretsKeys } from '../../shared/secrets';
import { filterTelemedVideoEncounters, getFhirResources } from './helpers';
import { validateRequestParameters } from './validateRequestParameters';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
import Oystehr, { BatchInput, BatchInputRequest, User } from '@oystehr/sdk';
import { APIGatewayProxyResult } from 'aws-lambda';
import { Operation } from 'fast-json-patch';
import { Appointment, Bundle, Encounter, Patient, Resource } from 'fhir/r4b';
import {
FHIR_EXTENSION,
RequiredProps,
SecretsKeys,
UpdateAppointmentRequestParams,
UpdateAppointmentResponse,
ZambdaInput,
createOystehrClient,
FHIR_EXTENSION,
getPatchBinary,
getPatchOperationToUpdateExtension,
getSecret,
RequiredProps,
topLevelCatch,
UpdateAppointmentRequestParams,
UpdateAppointmentResponse,
userHasAccessToPatient,
ZambdaInput,
} from 'utils';
import { checkOrCreateM2MClientToken, getUser } from '../../shared';

import { Operation } from 'fast-json-patch';
import { createUpdateUserRelatedResources, creatingPatientUpdateRequest } from '../../shared/appointment/helpers';
import { validateUpdateAppointmentParams } from './validateRequestParameters';
import { getSecret, SecretsKeys } from '../../shared/secrets';
import { getTelemedLocation } from '../telemed-create-appointment';
import { validateUpdateAppointmentParams } from './validateRequestParameters';

// Lifting up value to outside of the handler allows it to stay in memory across warm lambda invocations
let zapehrToken: string;
Expand Down
Loading

0 comments on commit e06a17a

Please sign in to comment.