(feat) Display patient phone number in appointment details and Excel export#2201
(feat) Display patient phone number in appointment details and Excel export#2201gabriel090 wants to merge 2 commits intoopenmrs:mainfrom
Conversation
| import { formatDate, formatDatetime, usePatient } from '@openmrs/esm-framework'; | ||
| import { usePatientAppointmentHistory } from '../../hooks/usePatientAppointmentHistory'; | ||
| import { getGender } from '../../helpers'; | ||
| import { getGender, getPatientPhoneNumberByUuid, getPatientPhoneNumber } from '../../helpers'; |
There was a problem hiding this comment.
| import { getGender, getPatientPhoneNumberByUuid, getPatientPhoneNumber } from '../../helpers'; | |
| import { getGender, getPatientPhoneNumberByUuid } from '../../helpers'; |
This is unused.
| ? patientInfo.telecom.map((telecomObj) => telecomObj?.value).join(', ') | ||
| : ''; | ||
| const patientInfo = await fetchPatientFromFhir2(appointment.patient.uuid); | ||
| const phoneNumber = getPatientPhoneNumber(patientInfo); |
There was a problem hiding this comment.
| const phoneNumber = getPatientPhoneNumber(patientInfo); | |
| const patientInfo = includePhoneNumbers ? await fetchPatientFromFhir2(appointment.patient.uuid) : null; | |
| const phoneNumber = includePhoneNumbers ? getPatientPhoneNumber(patientInfo) : ''; |
The includePhoneNumberInExcelSpreadsheet config flag is read but ignored, causing phone numbers to always be exported and FHIR2 patient data to always be fetched. This is a behavior regression and privacy risk.
| 'Appointment type': appointment.service?.name, | ||
| Date: formatDate(new Date(appointment.startDateTime), { mode: 'wide' }), | ||
| ...(includePhoneNumbers ? { 'Telephone number': phoneNumber } : {}), | ||
| 'Phone number': phoneNumber || '--', |
There was a problem hiding this comment.
| 'Phone number': phoneNumber || '--', | |
| ...(includePhoneNumbers ? { 'Phone number': phoneNumber || '--' } : {}), |
| const AppointmentDetails: React.FC<AppointmentDetailsProps> = ({ appointment }) => { | ||
| const { t } = useTranslation(); | ||
| const [isEnabledQuery, setIsEnabledQuery] = useState(false); | ||
| const [phoneNumber, setPhoneNumber] = useState<string>(''); |
There was a problem hiding this comment.
| const [phoneNumber, setPhoneNumber] = useState<string>(''); |
The component already has patient data via usePatient; the extra FHIR2 call is redundant and its result is never used. Additionally, telecom can include non-phone values (email, fax), which would be mislabeled as "Phone number".
| // Fetch phone number | ||
| useEffect(() => { | ||
| const fetchPhoneNumber = async () => { | ||
| const phone = await getPatientPhoneNumberByUuid(appointment.patient.uuid); | ||
| setPhoneNumber(phone); | ||
| }; | ||
|
|
||
| fetchPhoneNumber(); | ||
| }, [appointment.patient.uuid]); |
There was a problem hiding this comment.
| // Fetch phone number | |
| useEffect(() => { | |
| const fetchPhoneNumber = async () => { | |
| const phone = await getPatientPhoneNumberByUuid(appointment.patient.uuid); | |
| setPhoneNumber(phone); | |
| }; | |
| fetchPhoneNumber(); | |
| }, [appointment.patient.uuid]); | |
| const phoneNumber = getPatientPhoneNumber(patient ?? null); |
| {patient && patient?.telecom && patient.telecom.length > 0 ? ( | ||
| <div className={styles.labelContainer}> | ||
| <p className={styles.labelBold}>{t('phoneNumber', 'Phone number')}: </p> | ||
| <p className={styles.label}>{patient.telecom.map((contact) => contact.value).join(', ')}</p> |
There was a problem hiding this comment.
| {patient && patient?.telecom && patient.telecom.length > 0 ? ( | |
| <div className={styles.labelContainer}> | |
| <p className={styles.labelBold}>{t('phoneNumber', 'Phone number')}: </p> | |
| <p className={styles.label}>{patient.telecom.map((contact) => contact.value).join(', ')}</p> | |
| {phoneNumber ? ( | |
| <div className={styles.labelContainer}> | |
| <p className={styles.labelBold}>{t('phoneNumber', 'Phone number')}: </p> | |
| <p className={styles.label}>{phoneNumber}</p> |
| export async function getPatientPhoneNumberByUuid(patientUuid: string): Promise<string> { | ||
| try { | ||
| const patient = await fetchPatientFromFhir2(patientUuid); | ||
| return getPatientPhoneNumber(patient); | ||
| } catch (error) { | ||
| console.error('Error getting patient phone number:', error); | ||
| return ''; | ||
| } | ||
| } |
There was a problem hiding this comment.
| export async function getPatientPhoneNumberByUuid(patientUuid: string): Promise<string> { | |
| try { | |
| const patient = await fetchPatientFromFhir2(patientUuid); | |
| return getPatientPhoneNumber(patient); | |
| } catch (error) { | |
| console.error('Error getting patient phone number:', error); | |
| return ''; | |
| } | |
| } |
After the suggested component change, getPatientPhoneNumberByUuid is no longer used anywhere and should be removed.
Requirements
Summary
This ticket adds patient phone number display functionality to the appointments module. Phone numbers will be visible in the appointment details view and will be automatically included when downloading appointments to Excel. The implementation retrieves complete patient contact information from the FHIR2 API and handles cases where patients have multiple phone numbers by displaying them separated by commas.
When a phone number is unavailable, the system will display a placeholder to maintain consistent formatting.
This enhancement improves the usability of appointment management by making patient contact information readily accessible for both on-screen viewing and offline reference through Excel exports.
Screenshots
Related Issue
Other