"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.addAllergy = 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.addAllergy = {
    key: 'addAllergy',
    category: extensions_core_1.Category.EHR_INTEGRATIONS,
    title: 'Add Allergy',
    description: 'Adds allergy to the patient profile. If allergy.name is NKDA, we will document a structured NKDA in the patient chart instead of creating a patient allergy called "NKDA"',
    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.addAllergy({
            patient: fields.patientId,
            name: fields.name,
            start_date: fields.startDate,
            reaction: fields.reaction,
            severity: fields.severity,
        });
        await onComplete({
            data_points: {
                allergyId: String(id),
            },
        });
    },
};
//# sourceMappingURL=addAllergy.js.map