Skip to content

Commit

Permalink
update- from the comments on the PR
Browse files Browse the repository at this point in the history
  • Loading branch information
lucyjemutai committed Aug 16, 2024
1 parent 1dcf127 commit 6b5e053
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/esm-appointments-app/src/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Type, restBaseUrl, validators } from '@openmrs/esm-framework';
import { spaHomePage } from './constants';

export const configSchema = {
includeTelephoneNumbers: {
includeTelephoneNumbersInExcelDownload: {
_type: Type.Boolean,
_description: 'Whether to include phone numbers in the Excel export.',
_default: false,
Expand Down Expand Up @@ -151,5 +151,5 @@ export interface ConfigObject {
showUnscheduledAppointmentsTab: boolean;
useBahmniAppointmentsUI: boolean;
useFullViewPrivilege: boolean;
includeTelephoneNumbers: boolean;
includeTelephoneNumbersInExcelDownload: boolean;
}
15 changes: 7 additions & 8 deletions packages/esm-appointments-app/src/helpers/excel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { type Appointment } from '../types';
import { type ConfigObject } from '../config-schema';
import { moduleName } from '../constants';

async function fetchPatient(patientUuid: string): Promise<fhir.Patient> {
async function fetchCurrentPatient(patientUuid: string): Promise<fhir.Patient> {
// Fetch the FHIR Patient object because telephone numbers are not included
// in the standard appointments REST response
const apiUrl = `${fhirBaseUrl}/Patient/${patientUuid}`;
Expand All @@ -18,24 +18,23 @@ async function fetchPatient(patientUuid: string): Promise<fhir.Patient> {
*/
export async function downloadAppointmentsAsExcel(appointments: Array<Appointment>, fileName = 'Appointments') {
const config = await getConfig<ConfigObject>(moduleName);
const INCLUDE_TELEPHONE_NUMBERS = config.includeTelephoneNumbers ?? false;
const includeTelephoneNumbers = config.includeTelephoneNumbersInExcelDownload ?? false;

const appointmentsJSON = await Promise.all(
appointments.map(async (appointment: Appointment) => {
const patientinfo = await fetchPatient(appointment.patient.uuid);
const patientInfo = await fetchCurrentPatient(appointment.patient.uuid);
const phoneNumber =
INCLUDE_TELEPHONE_NUMBERS && patientinfo?.telecom
? patientinfo.telecom.map((telecomObj) => telecomObj?.value).join(', ')
includeTelephoneNumbers && patientInfo?.telecom
? patientInfo.telecom.map((telecomObj) => telecomObj?.value).join(', ')
: '';

return {
'Patient name': appointment.patient.name,
Gender: appointment.patient.gender === 'F' ? 'Female' : 'Male',
Age: appointment.patient.age,
Identifier: appointment.patient.identifier ?? '--',
'Appointment type': appointment.service?.name,
Date: formatDate(new Date(appointment.startDateTime), { mode: 'wide' }),
...(INCLUDE_TELEPHONE_NUMBERS ? { 'Telephone number': phoneNumber } : {}),
...(includeTelephoneNumbers ? { 'Telephone number': phoneNumber } : {}),
};
}),
);
Expand All @@ -47,7 +46,7 @@ export async function downloadAppointmentsAsExcel(appointments: Array<Appointmen
'Identifier',
'Appointment type',
'Date',
...(INCLUDE_TELEPHONE_NUMBERS ? ['Telephone number'] : []),
...(includeTelephoneNumbers ? ['Telephone number'] : []),
];

const worksheet = createWorksheet(appointmentsJSON);
Expand Down

0 comments on commit 6b5e053

Please sign in to comment.