"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createCareGap = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const zod_1 = require("zod");
const client_1 = require("../../client");
const settings_1 = require("../../settings");
const config_1 = require("./config");
exports.createCareGap = {
    key: 'createCareGap',
    category: extensions_core_1.Category.EHR_INTEGRATIONS,
    title: 'Create care gap',
    description: 'Create a care gap in Elation.',
    fields: config_1.fields,
    previewable: false,
    dataPoints: config_1.dataPoints,
    onActivityCreated: async (payload, onComplete, onError) => {
        const { fields: { patient_id, practice_id, created_date, status, detail, quality_program, definition_id, }, settings, } = (0, extensions_core_1.validate)({
            schema: zod_1.z.object({
                fields: config_1.FieldsValidationSchema,
                settings: settings_1.SettingsValidationSchema,
            }),
            payload,
        });
        // The care gap API uses a different base URL than the rest of the Elation API, see https://docs.elationhealth.com/reference/caregaps_post_caregaps_api__quality_program__caregap__post-1
        const caregapBaseUrl = settings.base_url.replace(/(.+\.)?elationemr\.com\/api\/2\.0\/?/, 'caregaps.$1elationemr.com/caregaps/api/');
        const api = (0, client_1.makeAPIClient)({
            ...payload.settings,
            baseUrl: caregapBaseUrl,
        });
        const careGap = await api.createCareGap({
            quality_program,
            definition_id,
            patient_id,
            practice_id,
            created_date,
            status,
            detail: detail !== null && detail !== void 0 ? detail : '',
        });
        await onComplete({
            data_points: {
                id: careGap.id,
            },
        });
    },
};
//# sourceMappingURL=createCareGap.js.map