"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createAppointmentNote = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const config_1 = require("./config");
const helpers_1 = require("../../helpers");
const lodash_1 = require("lodash");
exports.createAppointmentNote = {
    key: 'createAppointmentNote',
    category: extensions_core_1.Category.EHR_INTEGRATIONS,
    title: 'Create appointment note',
    description: 'Creates a note for a specific appointment',
    fields: config_1.fields,
    previewable: true,
    dataPoints: config_1.dataPoints,
    onActivityCreated: async (payload, onComplete, onError) => {
        const { fields: input, client, settings: { practiceId }, } = await (0, helpers_1.validatePayloadAndCreateClient)({
            fieldsSchema: config_1.FieldsValidationSchema,
            payload,
        });
        const res = await client.createAppointmentNote({
            practiceId,
            appointmentId: input.appointmentid,
            data: (0, lodash_1.omit)(input, ['appointmentid']),
        });
        if (res.success === 'true') {
            await onComplete();
            return;
        }
        await onError({
            events: [
                {
                    date: new Date().toISOString(),
                    text: { en: 'Unable to create the appointment note' },
                    error: {
                        category: 'SERVER_ERROR',
                        message: 'Unable to create the appointment note',
                    },
                },
            ],
        });
    },
};
//# sourceMappingURL=createAppointmentNote.js.map