|
|
|
|
@@ -5,7 +5,6 @@ import { RequestStatus } from '@/lib/types/audit';
|
|
|
|
|
import {
|
|
|
|
|
AvailableAppointmentsResponse,
|
|
|
|
|
BookTimeResponse,
|
|
|
|
|
ConfirmedLoadResponse,
|
|
|
|
|
ConnectedOnlineMethodName,
|
|
|
|
|
FailureReason,
|
|
|
|
|
} from '@/lib/types/connected-online';
|
|
|
|
|
@@ -99,7 +98,12 @@ export async function bookAppointment(
|
|
|
|
|
syncUserID: number,
|
|
|
|
|
startTime: string,
|
|
|
|
|
comments = '',
|
|
|
|
|
) {
|
|
|
|
|
): Promise<{
|
|
|
|
|
success: boolean;
|
|
|
|
|
reason?: FailureReason;
|
|
|
|
|
bookingCode: string | null;
|
|
|
|
|
clinicKey: string | null;
|
|
|
|
|
}> {
|
|
|
|
|
const logger = await getLogger();
|
|
|
|
|
const supabase = getSupabaseServerClient();
|
|
|
|
|
|
|
|
|
|
@@ -148,7 +152,7 @@ export async function bookAppointment(
|
|
|
|
|
supabase
|
|
|
|
|
.schema('medreport')
|
|
|
|
|
.from('connected_online_reservation')
|
|
|
|
|
.select('id')
|
|
|
|
|
.select('id,location_sync_id')
|
|
|
|
|
.eq('clinic_id', clinicId)
|
|
|
|
|
.eq('service_id', serviceId)
|
|
|
|
|
.eq('start_time', formattedStartTime)
|
|
|
|
|
@@ -202,8 +206,8 @@ export async function bookAppointment(
|
|
|
|
|
},
|
|
|
|
|
param: JSON.stringify({
|
|
|
|
|
ClinicID: clinic.id,
|
|
|
|
|
ServiceID: service.sync_id,
|
|
|
|
|
ClinicServiceID: service.id,
|
|
|
|
|
ServiceID: service.id,
|
|
|
|
|
ClinicServiceID: service.sync_id,
|
|
|
|
|
UserID: appointmentUserId,
|
|
|
|
|
SyncUserID: syncUserID,
|
|
|
|
|
StartTime: startTime,
|
|
|
|
|
@@ -216,6 +220,7 @@ export async function bookAppointment(
|
|
|
|
|
AddToBasket: false,
|
|
|
|
|
Key: dbClinic.key,
|
|
|
|
|
Lang: 'et',
|
|
|
|
|
Location: dbReservation.location_sync_id,
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
@@ -275,16 +280,34 @@ export async function bookAppointment(
|
|
|
|
|
'Booked time, updated reservation with id ' + updatedReservation?.id,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
await logRequestResult(
|
|
|
|
|
ExternalApi.ConnectedOnline,
|
|
|
|
|
ConnectedOnlineMethodName.BookTime,
|
|
|
|
|
RequestStatus.Success,
|
|
|
|
|
JSON.stringify(connectedOnlineBookingResponseData),
|
|
|
|
|
startTime.toString(),
|
|
|
|
|
service.id,
|
|
|
|
|
clinicId,
|
|
|
|
|
);
|
|
|
|
|
return { success: true };
|
|
|
|
|
if (responseParts[1]) {
|
|
|
|
|
await logRequestResult(
|
|
|
|
|
ExternalApi.ConnectedOnline,
|
|
|
|
|
ConnectedOnlineMethodName.BookTime,
|
|
|
|
|
RequestStatus.Success,
|
|
|
|
|
JSON.stringify(connectedOnlineBookingResponseData),
|
|
|
|
|
startTime.toString(),
|
|
|
|
|
service.id,
|
|
|
|
|
clinicId,
|
|
|
|
|
);
|
|
|
|
|
return {
|
|
|
|
|
success: true,
|
|
|
|
|
bookingCode: responseParts[1],
|
|
|
|
|
clinicKey: dbClinic.key,
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
logger.error(`Missing booking code: ${responseParts}`);
|
|
|
|
|
await logRequestResult(
|
|
|
|
|
ExternalApi.ConnectedOnline,
|
|
|
|
|
ConnectedOnlineMethodName.BookTime,
|
|
|
|
|
RequestStatus.Fail,
|
|
|
|
|
JSON.stringify(error),
|
|
|
|
|
startTime.toString(),
|
|
|
|
|
serviceId,
|
|
|
|
|
clinicId,
|
|
|
|
|
);
|
|
|
|
|
return { success: false, bookingCode: null, clinicKey: null };
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
logger.error(`Failed to book time, error: ${JSON.stringify(error)}`);
|
|
|
|
|
await logRequestResult(
|
|
|
|
|
@@ -296,41 +319,33 @@ export async function bookAppointment(
|
|
|
|
|
serviceId,
|
|
|
|
|
clinicId,
|
|
|
|
|
);
|
|
|
|
|
return { success: false, reason };
|
|
|
|
|
return { success: false, reason, bookingCode: null, clinicKey: null };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getConfirmedService(reservationCode: string) {
|
|
|
|
|
export async function getConfirmedService(
|
|
|
|
|
reservationCode: string,
|
|
|
|
|
clinicKey: string,
|
|
|
|
|
) {
|
|
|
|
|
try {
|
|
|
|
|
const response = await axios.post(
|
|
|
|
|
`${process.env.CONNECTED_ONLINE_URL!}/${ConnectedOnlineMethodName.ConfirmedLoad}`,
|
|
|
|
|
{
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json; charset=utf-8',
|
|
|
|
|
},
|
|
|
|
|
param: JSON.stringify({ Value: `${reservationCode}|7T624nlu|et` }),
|
|
|
|
|
const url = new URL(process.env.CONNECTED_ONLINE_CONFIRMED_URL!);
|
|
|
|
|
url.searchParams.set('code1', reservationCode);
|
|
|
|
|
url.searchParams.set('key', clinicKey);
|
|
|
|
|
url.searchParams.set('lang', 'et');
|
|
|
|
|
await fetch(url, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json; charset=utf-8',
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const responseData: ConfirmedLoadResponse = JSON.parse(response.data.d);
|
|
|
|
|
|
|
|
|
|
if (responseData?.ErrorCode !== 0) {
|
|
|
|
|
await logRequestResult(
|
|
|
|
|
ExternalApi.ConnectedOnline,
|
|
|
|
|
ConnectedOnlineMethodName.ConfirmedLoad,
|
|
|
|
|
RequestStatus.Fail,
|
|
|
|
|
JSON.stringify(responseData),
|
|
|
|
|
);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await logRequestResult(
|
|
|
|
|
ExternalApi.ConnectedOnline,
|
|
|
|
|
ConnectedOnlineMethodName.ConfirmedLoad,
|
|
|
|
|
RequestStatus.Success,
|
|
|
|
|
JSON.stringify(responseData),
|
|
|
|
|
'ok',
|
|
|
|
|
);
|
|
|
|
|
return responseData.Data;
|
|
|
|
|
return;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
await logRequestResult(
|
|
|
|
|
ExternalApi.ConnectedOnline,
|
|
|
|
|
|