"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.removePatientFromCohort = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const client_1 = require("../../client");
const errorHandler_1 = require("../../shared/errorHandler");
const generic_zod_1 = require("../../validation/generic.zod");
const fields_1 = require("./fields");
const dataPoints_1 = require("./dataPoints");
exports.removePatientFromCohort = {
    key: 'removePatientFromCohort',
    category: extensions_core_1.Category.EHR_INTEGRATIONS,
    title: 'Remove Patient from Cohort',
    description: 'Removes the specified Patient from a cohort.',
    fields: fields_1.removePatientFromCohortFields,
    previewable: true,
    supports_automated_retries: true,
    dataPoints: dataPoints_1.removePatientFromCohortDataPoints,
    onActivityCreated: async (payload, onComplete, onError) => {
        try {
            const cohortId = generic_zod_1.stringId.parse(payload.fields.cohortId);
            const patientId = generic_zod_1.stringId.parse(payload.fields.patientId);
            const api = (0, client_1.createMetriportApi)(payload.settings);
            const { message, cohort } = await api.removePatientsFromCohort({
                cohortId,
                patientIds: [patientId],
            });
            await onComplete({
                data_points: {
                    message,
                    cohort: JSON.stringify(cohort),
                },
            });
        }
        catch (err) {
            await (0, errorHandler_1.handleErrorMessage)(err, onError);
        }
    },
};
//# sourceMappingURL=removePatientFromCohort.js.map