"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createVisitNote = void 0;
const zod_1 = require("zod");
const extensions_core_1 = require("@awell-health/extensions-core");
const settings_1 = require("../../settings");
const client_1 = require("../../client");
const config_1 = require("./config");
exports.createVisitNote = {
    key: 'createVisitNote',
    category: extensions_core_1.Category.EHR_INTEGRATIONS,
    title: 'Create Visit Note',
    description: 'Create a visit note for a patient. This action will create a visit note in the patient chart.',
    fields: config_1.fields,
    previewable: true,
    dataPoints: config_1.dataPoints,
    onEvent: async ({ payload, onComplete }) => {
        const { fields, settings } = (0, extensions_core_1.validate)({
            schema: zod_1.z.object({
                fields: config_1.FieldsValidationSchema,
                settings: settings_1.SettingsValidationSchema,
            }),
            payload,
        });
        const api = (0, client_1.makeAPIClient)(settings);
        const { id } = await api.createVisitNote({
            patient: fields.patientId,
            chart_date: new Date().toISOString(),
            document_date: new Date().toISOString(),
            template: fields.template,
            physician: fields.physicianId,
            bullets: [
                {
                    text: fields.text,
                    author: fields.authorId,
                    category: fields.category,
                },
            ],
            type: fields === null || fields === void 0 ? void 0 : fields.type,
            confidential: fields === null || fields === void 0 ? void 0 : fields.confidential,
        });
        await onComplete({
            data_points: {
                visitNoteId: String(id),
            },
        });
    },
};
//# sourceMappingURL=createVisitNote.js.map