Skip to content

Commit 9694b93

Browse files
committed
fix: claim submission date of service
1 parent ab4a7d9 commit 9694b93

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

packages/zambdas/src/shared/candid.ts

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ import {
7272
getPayerId,
7373
getPaymentVariantFromEncounter,
7474
getSecret,
75+
getTimezone,
7576
INVALID_INPUT_ERROR,
7677
isTelemedAppointment,
7778
mapOrderStatusToFhir,
@@ -81,6 +82,7 @@ import {
8182
PaymentVariant,
8283
Secrets,
8384
SecretsKeys,
85+
TIMEZONES,
8486
} from 'utils';
8587
import { CODE_SYSTEM_CMS_PLACE_OF_SERVICE, emCodeOptions } from 'utils/lib/helpers/rcm';
8688
import { getAccountAndCoverageResourcesForPatient } from '../ehr/shared/harvest';
@@ -328,10 +330,7 @@ async function candidCreateEncounterRequest(
328330
let dateOfServiceString: string | undefined;
329331

330332
if (appointmentStart) {
331-
const dateOfService = DateTime.fromISO(appointmentStart);
332-
if (dateOfService.isValid) {
333-
dateOfServiceString = dateOfService.toISODate();
334-
}
333+
dateOfServiceString = getLocalDateOfService(appointmentStart, location);
335334
}
336335

337336
// Note: dateOfService field must not be provided as service line date of service is already sent
@@ -409,10 +408,7 @@ async function candidCreateEncounterRequest(
409408
diagnosisPointers: [primaryDiagnosisIndex],
410409
dateOfService:
411410
dateOfServiceString ||
412-
assertDefined(
413-
DateTime.fromISO(assertDefined(input.appointment.start, 'Appointment start')).toISODate(),
414-
'Service line date'
415-
),
411+
getLocalDateOfService(assertDefined(appointment.start, 'Appointment start'), location),
416412
},
417413
];
418414
}),
@@ -1068,6 +1064,11 @@ function convertCoverageRelationshipToCandidRelationship(relationship: string):
10681064
}
10691065
}
10701066

1067+
function getLocalDateOfService(appointmentStart: string, location: Location | undefined): string {
1068+
const timezone = location ? getTimezone(location) : TIMEZONES[0];
1069+
return DateTime.fromISO(appointmentStart).setZone(timezone).toISODate()!;
1070+
}
1071+
10711072
const fetchFHIRPatientAndAppointmentFromEncounter = async (
10721073
encounterId: string,
10731074
oystehr: Oystehr
@@ -1244,13 +1245,12 @@ async function candidCreateEncounterFromAppointmentRequest(
12441245

12451246
// Use appointment start time for date of service instead of signed date
12461247
const appointmentStart = appointment.start;
1248+
console.log(`Appointment start time: ${appointmentStart}`);
12471249
let dateOfServiceString: string | undefined;
12481250

12491251
if (appointmentStart) {
1250-
const dateOfService = DateTime.fromISO(appointmentStart);
1251-
if (dateOfService.isValid) {
1252-
dateOfServiceString = dateOfService.toISODate();
1253-
}
1252+
dateOfServiceString = getLocalDateOfService(appointmentStart, location);
1253+
console.log(`Using appointment start time for date of service: ${dateOfServiceString}`);
12541254
}
12551255

12561256
const serviceLines: ServiceLineCreate[] = [];
@@ -1272,11 +1272,7 @@ async function candidCreateEncounterFromAppointmentRequest(
12721272
units: ServiceLineUnits.Un,
12731273
diagnosisPointers: [primaryDiagnosisIndex],
12741274
dateOfService:
1275-
dateOfServiceString ||
1276-
assertDefined(
1277-
DateTime.fromISO(assertDefined(appointment.start, 'Appointment start')).toISODate(),
1278-
'Service line date'
1279-
),
1275+
dateOfServiceString ?? getLocalDateOfService(assertDefined(appointment.start, 'Appointment start'), location),
12801276
});
12811277
});
12821278

@@ -1311,7 +1307,7 @@ async function candidCreateEncounterFromAppointmentRequest(
13111307
dateOfService:
13121308
dateOfServiceString ||
13131309
assertDefined(
1314-
DateTime.fromISO(assertDefined(appointment.start, 'Appointment start')).toISODate(),
1310+
getLocalDateOfService(assertDefined(appointment.start, 'Appointment start'), location),
13151311
'Service line date'
13161312
),
13171313
});

0 commit comments

Comments
 (0)