"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.findAppointments = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const settings_1 = require("../settings");
const client_1 = require("../client");
const appointment_zod_1 = require("../validation/appointment.zod");
const zod_1 = require("zod");
const fields = {
    patientId: {
        id: 'patientId',
        label: 'Patient ID',
        type: extensions_core_1.FieldType.NUMERIC,
        description: 'Patient ID',
    },
    physicianId: {
        id: 'physicianId',
        label: 'Physician ID',
        type: extensions_core_1.FieldType.NUMERIC,
        description: 'Physician ID',
        required: false,
    },
    practiceId: {
        id: 'practiceId',
        label: 'Practice ID',
        type: extensions_core_1.FieldType.NUMERIC,
        description: 'Practice ID',
        required: false,
    },
    from_date: {
        id: 'from_date',
        label: 'From Date',
        type: extensions_core_1.FieldType.DATE,
        description: 'Date from which to filter appointments',
    },
    to_date: {
        id: 'to_date',
        label: 'To date',
        type: extensions_core_1.FieldType.DATE,
        description: 'Date to which appointments are filtered',
        required: false,
    },
    event_type: {
        id: 'event_type',
        label: 'Event Type',
        type: extensions_core_1.FieldType.STRING,
        description: 'Event Type (`appointment` or leave empty)',
        required: false,
    },
};
const dataPoints = {
    appointments: {
        key: 'appointments',
        valueType: 'json',
    },
    appointment_exists: {
        key: 'appointment_exists',
        valueType: 'boolean',
    },
};
exports.findAppointments = {
    key: 'findAppointment',
    category: extensions_core_1.Category.EHR_INTEGRATIONS,
    title: 'Find Appointment',
    description: 'Retrieve appointments for a given patient, physician, practice, and/or times',
    fields,
    previewable: true,
    dataPoints,
    onActivityCreated: async (payload, onComplete, onError) => {
        const { fields, settings } = (0, extensions_core_1.validate)({
            schema: zod_1.z.object({
                fields: appointment_zod_1.FindAppointmentFieldSchema,
                settings: settings_1.SettingsValidationSchema,
            }),
            payload,
        });
        const client = (0, client_1.makeAPIClient)(settings);
        const resp = await client.findAppointments(fields);
        await onComplete({
            data_points: {
                appointments: JSON.stringify(resp),
                appointment_exists: resp.length > 0 ? 'true' : 'false',
            },
        });
    },
};
//# sourceMappingURL=findAppointments.js.map