diff --git a/packages/telemed-ehr/app/src/components/EmployeeInformationForm.tsx b/packages/telemed-ehr/app/src/components/EmployeeInformationForm.tsx index f070ff19..cb6b6a58 100644 --- a/packages/telemed-ehr/app/src/components/EmployeeInformationForm.tsx +++ b/packages/telemed-ehr/app/src/components/EmployeeInformationForm.tsx @@ -55,6 +55,8 @@ interface EmployeeForm { lastName: string; nameSuffix: string; roles: string[]; + phoneNumber: string; + npi: string; } const AVAILABLE_ROLES: { @@ -150,22 +152,6 @@ export default function EmployeeInformationForm({ console.log('existingUser', existingUser); - let npiText = 'n/a'; - if (existingUser?.profileResource?.identifier) { - const npi = existingUser.profileResource.identifier.find((identifier) => identifier.system === FHIR_IDENTIFIER_NPI); - if (npi && npi.value) { - npiText = npi.value; - } - } - - let phoneText = ''; - if (existingUser?.profileResource?.telecom) { - const phone = existingUser.profileResource.telecom.find((tel) => tel.system === 'sms')?.value; - if (phone) { - phoneText = phone; - } - } - let photoSrc = ''; if (existingUser?.profileResource?.photo) { const photo = existingUser.profileResource.photo[0]; @@ -201,6 +187,26 @@ export default function EmployeeInformationForm({ setValue('middleName', middleName); setValue('lastName', lastName); setValue('nameSuffix', nameSuffix); + + let phoneText = ''; + if (existingUser?.profileResource?.telecom) { + const phone = existingUser.profileResource.telecom.find((tel) => tel.system === 'sms')?.value; + if (phone) { + phoneText = phone; + } + } + setValue('phoneNumber', phoneText); + + let npiText = 'n/a'; + if (existingUser?.profileResource?.identifier) { + const npi = existingUser.profileResource.identifier.find( + (identifier) => identifier.system === FHIR_IDENTIFIER_NPI, + ); + if (npi && npi.value) { + npiText = npi.value; + } + } + setValue('npi', npiText); } }, [existingUser, setValue]); @@ -229,6 +235,8 @@ export default function EmployeeInformationForm({ nameSuffix: data.nameSuffix, selectedRoles: data.roles, licenses: newLicenses, + phoneNumber: data.phoneNumber, + npi: data.npi, }); } catch (error) { console.log(`Failed to update user: ${error}`); @@ -334,16 +342,19 @@ export default function EmployeeInformationForm({ disabled: true, }} /> - ( + + )} /> @@ -420,7 +431,21 @@ export default function EmployeeInformationForm({ /> )} /> - + ( + + )} + /> {isProviderRoleSelected && ( <> diff --git a/packages/telemed-ehr/app/src/types/types.ts b/packages/telemed-ehr/app/src/types/types.ts index 16af1f72..84eae09a 100644 --- a/packages/telemed-ehr/app/src/types/types.ts +++ b/packages/telemed-ehr/app/src/types/types.ts @@ -38,6 +38,8 @@ export interface UpdateUserParameters { nameSuffix?: string; selectedRoles?: string[] | undefined; licenses?: PractitionerLicense[]; + phoneNumber?: string; + npi?: string; // locations: Location[]; } diff --git a/packages/telemed-ehr/zambdas/src/update-user/index.ts b/packages/telemed-ehr/zambdas/src/update-user/index.ts index 665c2064..9dfb2cc2 100644 --- a/packages/telemed-ehr/zambdas/src/update-user/index.ts +++ b/packages/telemed-ehr/zambdas/src/update-user/index.ts @@ -1,6 +1,6 @@ import { APIGatewayProxyResult } from 'aws-lambda'; import { Practitioner, HumanName } from 'fhir/r4'; -import { PractitionerLicense, Secrets } from 'ehr-utils'; +import { FHIR_IDENTIFIER_NPI, PractitionerLicense, Secrets } from 'ehr-utils'; import { RoleType } from '../../../app/src/types/types'; import { getSecret } from '../shared'; import { topLevelCatch } from '../shared/errors'; @@ -19,6 +19,8 @@ export interface UpdateUserInput { nameSuffix?: string; selectedRoles?: RoleType[]; licenses?: PractitionerLicense[]; + phoneNumber?: string; + npi?: string; } let m2mtoken: string; @@ -27,7 +29,7 @@ export const index = async (input: ZambdaInput): Promise console.group('validateRequestParameters'); const validatedParameters = validateRequestParameters(input); console.log('validatedParameters:', JSON.stringify(validatedParameters, null, 4)); - const { secrets, userId, firstName, middleName, lastName, nameSuffix, selectedRoles, licenses } = + const { secrets, userId, firstName, middleName, lastName, nameSuffix, selectedRoles, licenses, phoneNumber, npi } = validatedParameters; console.groupEnd(); console.debug('validateRequestParameters success'); @@ -98,14 +100,40 @@ export const index = async (input: ZambdaInput): Promise id: practitionerId, name: name ? [name] : undefined, qualification: practitionerQualificationExtension, + telecom: phoneNumber ? [{ system: 'sms', value: phoneNumber }] : undefined, }); } else { + const existingTelecom = existingPractitionerResource.telecom || []; + const smsIndex = existingTelecom.findIndex((tel) => tel.system === 'sms'); + const updatedTelecom = [...existingTelecom]; + if (phoneNumber) { + if (smsIndex >= 0) { + updatedTelecom[smsIndex] = { system: 'sms', value: phoneNumber }; + } else { + updatedTelecom.push({ system: 'sms', value: phoneNumber }); + } + } + if (npi) { + if (!existingPractitionerResource.identifier) { + existingPractitionerResource.identifier = []; + } + const npiIndex = existingPractitionerResource.identifier.findIndex((id) => id.system === FHIR_IDENTIFIER_NPI); + if (npiIndex >= 0) { + existingPractitionerResource.identifier[npiIndex].value = npi; + } else { + existingPractitionerResource.identifier.push({ + system: FHIR_IDENTIFIER_NPI, + value: npi, + }); + } + } await fhirClient.updateResource({ ...existingPractitionerResource, identifier: existingPractitionerResource.identifier, photo: existingPractitionerResource.photo, name: name ? [name] : undefined, qualification: practitionerQualificationExtension, + telecom: updatedTelecom, }); } } catch (error: unknown) { diff --git a/packages/telemed-ehr/zambdas/src/update-user/validateRequestParameters.ts b/packages/telemed-ehr/zambdas/src/update-user/validateRequestParameters.ts index ab490ff3..d3873e24 100644 --- a/packages/telemed-ehr/zambdas/src/update-user/validateRequestParameters.ts +++ b/packages/telemed-ehr/zambdas/src/update-user/validateRequestParameters.ts @@ -7,7 +7,9 @@ export function validateRequestParameters(input: ZambdaInput): UpdateUserInput { throw new Error('No request body provided'); } - const { userId, firstName, middleName, lastName, nameSuffix, selectedRoles, licenses } = JSON.parse(input.body); + const { userId, firstName, middleName, lastName, nameSuffix, selectedRoles, licenses, phoneNumber, npi } = JSON.parse( + input.body, + ); if ( userId === undefined @@ -36,5 +38,7 @@ export function validateRequestParameters(input: ZambdaInput): UpdateUserInput { licenses, // locations, secrets: input.secrets, + phoneNumber: phoneNumber ? phoneNumber.trim() : phoneNumber, + npi: npi ? npi.trim() : npi, }; }